Question by
Blast73 · Nov 18, 2015 at 06:39 AM ·
c#unity 5scripting problemcollision detection
Collision with a wall when I only want it with the player
I'm making an FPS with enemy AI. The AI follows the player, navigating around walls. If the enemy touches the player, it's game over. My problem is that if the enemy touches anything at all it ends the game. Here is the simple script I have on the enemy:
using UnityEngine;
using System.Collections;
public class Santa : MonoBehaviour {
public Collider myPlayer;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter (Collider myPlayer) {
Application.LoadLevel("gameover");
}
}
The public Collider is what I attach my first person controller to. Does anyone know why this isn't working?
Comment
Best Answer
Answer by Blast73 · Nov 18, 2015 at 02:38 AM
I got it working. I just added
if (myPlayer.attachedRigidbody)
right underneath the OnTriggerEnter