- Home /
Scripting a grenade
I am trying to make my grenade explode but when i throw it nothing happens. can someone please help me. my script is the one i have attached to grenade prefab
var creationTime = Time.time; var explosionPrefab : Transform;
function Awake() { creationTime = Time.time; }
function Update () { if(Time.time < (creationTime-3)) { Destroy(gameObject); Instantiate(explosionPrefab, transform.position, Quaternion.identity); } }
Answer by SilverTabby · Jul 27, 2011 at 12:51 AM
You are checking if The current time is less than when you created it. Right now the grenade will only go off if you invent a time machine.
You need to check if Time.time is GREATER than start time PLUS (not minus, another problem you had) detonation time.
Answer by killerstud3 · Jul 27, 2011 at 01:13 AM
thankyou soooooo much
1) Do not post comments as answers. It messes up the search system, and people who use this website generally do not respond well to people who do so.
2) If your question has been answered, please press the check button next to the answer. It marks the question as finished, and it improves the search system's ability to find relevant answers. Also, I have seen people on this website not post answers to questions for the sole reason that the person who asks them (someone like yourself) has not marked answers as accepted.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do you make a grenade stick to different surfaces? 1 Answer
How to import the object from server to unity 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer