- Home /
Problem resolved without definite reason.
Disappearing Pickups
I have a few pickups in a game of mine that...disappear. I have them set up in the scene, and you can see them in the game right away. They disappear (almost) immediately, though, and are removed from the hierarchy in the middle of game play. The two pickups have separate scripts:
Script 1:
var countsAs : int = 1;
var gravity : float = 16;
function OnCollisionEnter (pickup : Collision)
{
if(pickup.gameObject.name == "MainM"){
PlayerStat._numoftomatos += countsAs;
print("Before Destroy");
Destroy(gameObject);
print("After Destroy");
}
}
Script 2:
var rotation : float = 20;
function OnCollisionEnter (Main_m : Collision)
{
if(Main_m.gameObject.name == "MainM"){
PlayerStat._numofkeys += 1;
Destroy(gameObject);
}
}
function Update(){
transform.rotation.y += rotation * Time.deltaTime;
}
Edit: changed name of collision.
Answer by Berenger · Jun 11, 2012 at 06:27 PM
[WRONG : The objects are removed from the hierarchy]
The way you handle the collision is a little confusing, what is MainM ? Anyway, your pickups are probably going through the ground. By modifying the position.y, you're only modifying the matrix, not the physic, so it won't collide with the ground. Use a rigidbody, the gravity is applied by default.
[/WRONG]
Ok, second shot : use prints before or after the Destroy. My guess is there is a collision at the start, you need to figure out why and with what. If it still wrong, I'll move my answer to the comments so you can be unanswered.
...The objects are removed in the hierarchy...
Also, I now see the many misspellings in my question. $$anonymous$$y internet connection was slowing to a stop... I was lucky to get the question submitted... I'll fix any errors.
Edit: "$$anonymous$$ain$$anonymous$$" is the name of the main character in the game. I don't have a specific reason why I named the one collision after that character...
The prints do not show...so the destroy function within the script isn't causing it. I also removed the gravity portion of the script and will use a rigidbody (since I need it for collisions anyway).
Edit: I found only two other scripts with a Destroy function, with both referencing the objects they are attached to. These scripts are not attached to the objects that are being referenced in this question...
The problem is (see$$anonymous$$gly) resolved... I don't know how, but it's okay if it is working!
Thanks, @Berenger
Follow this Question
Related Questions
Bugs in a pick up items script. 2 Answers
How do I stop my objects from going through walls when I pick them up and drop them down? 2 Answers
How can i change the scriptable object variable in child script (if it's possible) 0 Answers
Unity doesn't start on Windows 7 x64? 8 Answers
Weird Crash after Upgrading to 3.5.2 1 Answer