Hi,
I’m trying to delete an object when it collides with a box only when a key is down. In this case the “j” key. I tried working with OnTiggerStay/OnTriggerEnter, which worked, but the response time was very bad. It would only seem to work when the object came in contact with the boxes edge. So in this example I have an object “HighHat”, when it collides with any other object and the j key is down I want it to disappear. If anyone could help me out that would be great. I’m not to savvy with Unity or C#. So if you were to ask “why did you do ____?” I unfortunately don’t really have a good response. I did it because it worked the best at the time.
Thanks,
using UnityEngine;
using System.Collections;
public class DestroyHH : MonoBehaviour
{
public int scoreValue;
private GameController gameController;
void Start ()
{
GameObject gameControllerObject = GameObject.FindWithTag ("GameController");
if (gameControllerObject != null)
{
gameController = gameControllerObject.GetComponent <GameController>();
}
if (gameController == null)
{
Debug.Log ("Cannot find 'GameController' script");
}
}
void OnCollisionEnter(Collider other)
{
if (other.tag == "HighHat")
{
if(Input.GetKeyDown (KeyCode.J))
{
Destroy (other.gameObject);
gameController.AddScore (scoreValue);
}
}
}
}