- Home /
destroy object when on floor Help
i have a soda can that when u drink it gives health , etc... now when i drop it on the floor i want it to be destroyed. Problem is i have var that says onfloor and works when its off floor and whens its not, but it wont destroy it...
var isDone : boolean;
var isOnFloor : boolean;
var isCurrentGun : boolean;
var isReady : boolean = true;
var isPlayed : boolean;
var healthGiven : boolean;
var sodaDrinkAudio : AudioClip;
var playerMovementScript : PlayerMovementScript;
var health : AdvancedHealth;
var empty_weapon : GameObject;
var objectToDestroy : GameObject;
var Destroyit : boolean;
function FixedUpdate (){
if(playerMovementScript.currentGun == gameObject)
{
isCurrentGun = true;
isOnFloor = false;
}else{
isCurrentGun = false;
isOnFloor = true;
}
if(isOnFloor && !isCurrentGun && healthGiven && isPlayed && isDone)
{
Destroyit = true;
}
}
function Update () {
if(Input.GetKeyDown("u") && isReady && !healthGiven && !isPlayed && playerMovementScript.currentGun == gameObject)
{
healthGiven = true;
isPlayed = true;
if(healthGiven && isPlayed)
{
isReady = false;
giveHealthSoda();
audio.PlayOneShot(sodaDrinkAudio);
}
}
}
function giveHealthSoda () {
yield WaitForSeconds(5);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.08);
health.maxHealth += 1;
yield WaitForSeconds(.05);
isDone = true;
yield WaitForSeconds(3.0);
if (Destroyit == true)
{
yield WaitForSeconds (3.0);
Destroy (objectToDestroy);
}
}
This is a mess ....
Remove all the unnecessary spaces in the script, it is impossible to read and cross-reference variables like this.
Fixed Update is there for one basic purpose : to affect rigidbodys. If you are not modifying velocity or adding force, do Not use FixedUpdate.
There must be something flawed in your logic, so you are never setting DestroyIt to true. Again, it is impossible to check this without wearing out my mouse scroll-wheel
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
Destroy Istantiated objects after some time (different for each instance) 1 Answer
Destroy On Collision 4 Answers
Enemy's wont die if spawned 1 Answer
Help with Destroy GameObject Code 1 Answer