为什么我不会因为某些原因而不能回应我的简单转折论点? (2D)

时间:2018-05-15 19:02:01

标签: c# unity3d transform sprite rigid-bodies

我有一个2d精灵,我只是想按一下按钮就可以翻转它的x轴。出于某种原因,即使所有其他论点都是如此,它也不会回应我。我没有收到任何错误消息。有没有人有办法解决吗?它让我发疯,因为我已经和敌人做了这么多次,现在突然间什么也没发生。参数在Flip和Flipper函数中,但是我把剩下的参数留在那里,你看到另一个可能阻止翻转发生的参数。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class dragoonDetection : MonoBehaviour {

private Rigidbody2D rb;
private Animator anim;
[HideInInspector]
public bool flight;
[HideInInspector]
public regDragon detector;
public float flightHeight;
public float flightDistance;
private bool facingRight = true;
private bool state1;
public float changeTimer = 0f;
public float changeDelay = 0.5f;
public float attackTimer = 0;
public float attackDelay = 1f;
public float speed = 1f;
public Transform Player; 


void Start ()
{
    rb = GetComponent<Rigidbody2D> ();
    anim = GetComponent<Animator> ();
}

void Update()

{
    Detected ();
    ChangeTimes (); 
    StateChanger ();  
    Flip ();
}


void Flipper()
{
        facingRight = !facingRight;
        Vector3 theScale = transform.localScale;
        theScale.x *= -1;
        transform.localScale = theScale;
}

void Flip()
{

    if (facingRight && Input.GetKeyDown (KeyCode.LeftArrow)) {
        Flipper ();
        Debug.Log ("left");
    }

    if (!facingRight && Input.GetKeyDown (KeyCode.RightArrow)) {
        Flipper ();
        Debug.Log ("right");
    }

}

void Detected()
{
    if (detector == null) {
        return;
    } else 

    {
        if (detector.detected) {
            flight = true;
            anim.SetTrigger ("flight");
            rb.velocity = new Vector2 (rb.velocity.x, flightHeight);
            changeDelay -= Time.deltaTime;
        }
    }
}

void ChangeTimes ()
{
    if (changeDelay <= 0 && flight) {
        state1 = true;
    }
}

void StateChanger ()
{
    if (state1) {

        flightHeight = 0f;
    }
}

void OnTriggerEnter2D (Collider2D other)
{
    if (other.gameObject.tag == ("arrow")) {
        flight = true;
        anim.SetTrigger ("flight");
    }
}
}

1 个答案:

答案 0 :(得分:0)

我明白了。动画本身出了点问题。 IDK是怎么发生的,因为那也很好。没有额外的参数或动画发生的具体位置。但我重新插入精灵,现在它工作正常。我的Unity最近一直在做随意的行动,那些永远正常工作的东西突然间无缘无故地开始反叛(我现在已经有5段了)。不过没关系。谢谢大家投入两分钱。