- Home /
Broking objects
using UnityEngine;
using System.Collections;
public class broke : MonoBehaviour {
public GameObject Player;
public GameObject Tre;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
void OnTriggerEnter(Collider Player){
if(Input.GetKeyDown(KeyCode.B)){
Destroy(Tre);
}
}
What's wrong??
Answer by BloodyNyash · Feb 16, 2014 at 10:47 AM
A namespace can only contain types and namespace declarations. What is this??
Answer by robertbu · Feb 16, 2014 at 07:49 AM
You are using Input.GetKeyDown(). This will only be true for a single frame. The chance that the key will go down in the same frame as the collision is entered is very small. I'm not sure of your intent here, but you could change the code to use Input.GetKey() which returns true as long as the key is held down. Or you could use OnCollisionStay() instead of OnCollisionEnter().
Your answer
Follow this Question
Related Questions
Problem with creating static bool... 1 Answer
Play sound by pressing button 2 Answers
Working with namespace, correct way to set up? 2 Answers
Help with Scripting (Boolean) 1 Answer
please,help me with script 3 Answers