Hey guys.
For some reason this code doesn’t work. When the player collides into the Enemy (which is a cube like the player) it doesn’t print the (I hit enemy) I have no idea why
I followed this guys tutorial
using UnityEngine;
using System.Collections;
public class EnemyPatrol : MonoBehaviour {
public Transform[] patrolPoints;
public float moveSpeed;
private int currentPoint;
// Use this for initialization
void Start () {
transform.position = patrolPoints [0].position;
currentPoint = 0;
}
// Update is called once per frame
void Update () {
if (transform.position == patrolPoints[currentPoint].position)
{
currentPoint++;
}
if (currentPoint >= patrolPoints.Length)
{
currentPoint = 0;
}
transform.position = Vector3.MoveTowards(transform.position, patrolPoints[currentPoint].position, moveSpeed * Time.deltaTime);
}
void OnCollisionEnter(Collision Other)
{
if (Other.transform.tag == "Enemy")
{
print ("I hit the enemy");
}
}
}