using UnityEngine;
using System.Collections;
public class changedirection : MonoBehaviour {
void OnCollisionEnter(Collision col)
{
if (col.gameObject.name == "soldier")
{
GameObject go = col.gameObject;
Move move = go.GetComponent<Move>();
move.direction = -1;
}
}
}
Run Code Online (Sandbox Code Playgroud)
碰撞的两个物体都是触发器,抱歉没有统一编程超过一年