- Home /
This question was
closed Aug 22, 2015 at 03:15 AM by
getyour411 for the following reason:
Use OnTriggerStay
Question by
omegacraft · Aug 22, 2015 at 03:15 AM ·
c#collisiontriggers
Always check OnTriggerEnter
How do I check if an object is in the trigger area, but I want to check it every frame. I tried the usual way to do it but when I enter it just moves once instead of like in the update function, anyway here is my script:
using UnityEngine;
using System.Collections;
public class EnemyHealth : MonoBehaviour {
public int health;
public Transform player;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (health <= 0) {
Destroy (gameObject);
}
}
void OnTriggerEnter (Collider other) {
if (other.gameObject.tag == "Player") {
//I want it to move every frame as long as it is in the trigger
transform.position += new Vector3 (-player.position.x, transform.position.y, -player.position.z);
}
}
void OnTriggerExit (Collider other) {
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612000946im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Light rarely turns on 1 Answer
How do I enable and disable a ragdoll using c#? 0 Answers
Trigger collision with multiple objects suddenly becomes unreliable. 1 Answer
Detecting collisions 3 Answers