Unity 3D - 2D

时间:2016-09-30 15:42:28

标签: unity3d unity5

我遇到Unity 2D对撞机的问题,如本视频所示:https://youtu.be/AMof6lJNtNk

红墙正在“杀死”我,但是在比赛开始/重生之后。我碰到了两面墙(砖比红墙有更小的对撞机)而且我很快就死了,但是如果我先碰到砖头,那么到红墙我就不会死。为什么? 在这两种情况下我都不想死。

using UnityEngine;
using System.Collections;

public class MovementScript : MonoBehaviour {
    public float speed = 1.0f;
    Vector3 spawn;

    // Use this for initialization
    void Start () {
        GetComponent ().freezeRotation = true;
        spawn = GetComponent ().transform.position;
    }

    // Update is called once per frame
    void Update () {
        //Debug.Log ("Vertical: " + Input.GetAxis ("Vertical"));
        if (Input.GetAxis ("Vertical") > 0) {
            GetComponent ().velocity = new Vector2 (0, 1)*speed;
        } else if (Input.GetAxis ("Vertical")  ().velocity = new Vector2 (0, -1)*speed;
        }

        if (Input.GetAxis ("Horizontal") > 0) {
            GetComponent ().velocity = new Vector2 (1, 0)*speed;
        } else if (Input.GetAxis ("Horizontal")  ().velocity = new Vector2 (-1, 0)*speed;
        }
    }

    void OnTriggerEnter2D (Collider2D col){
        Debug.Log ("Koliduje!");
        if (col.transform.tag == "Respawn") {
            Debug.Log ("Skułeś się!");
            GetComponent ().transform.position = spawn;
        }
    }
}

0 个答案:

没有答案