Unity 2d - 我想在自上而下的游戏中移除图像的旋转

时间:2018-05-27 12:18:32

标签: c# unity3d

我想修复代码 因此,在转换到下一个点时图像不会旋转 我试图解决它,但不能

对写作的错误道歉,我不会说英语

enter image description here

    [SerializeField]
    private Transform[] patrolPoints;
    Transform currentPatrolPoint;
    int currentPatrolIndex;
    protected override void Start()
    {
        currentPatrolIndex = 0;
        currentPatrolPoint = patrolPoints[currentPatrolIndex];
        base.Start();
    }

    protected override void Update()
    {
        transform.Translate(Vector3.up * Time.deltaTime * MySpeed);
      
        if (Vector3.Distance(transform.position,currentPatrolPoint.position)<0.1f)
        {
            if(currentPatrolIndex+1<patrolPoints.Length)
            {
                currentPatrolIndex++;
            }
            else
            {
                currentPatrolIndex = 0;
            }
            currentPatrolPoint = patrolPoints[currentPatrolIndex];
        }

        Vector3 patrolPointDirection = currentPatrolPoint.position - transform.position;
        float angle = Mathf.Atan2(patrolPointDirection.y, patrolPointDirection.x) * Mathf.Rad2Deg - 90f;
        Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
        transform.rotation = Quaternion.RotateTowards(transform.rotation, q,180f);
     
  
    }

1 个答案:

答案 0 :(得分:0)

如果您不希望它旋转,请移除此部分,这会旋转GameObject:

float angle = Mathf.Atan2(patrolPointDirection.y, patrolPointDirection.x) * Mathf.Rad2Deg - 90f;
Quaternion q = Quaternion.AngleAxis(angle, Vector3.forward);
transform.rotation = Quaternion.RotateTowards(transform.rotation, q,180f);

您可以从代码中删除任何仅用于transform.rotation的变量。