x


[Closed] 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.

more ▼

asked Jun 11 '12 at 05:38 PM

You! gravatar image

You!
447 8 14 16

(comments are locked)
10|3000 characters needed characters left

The question has been closed Jun 11 '12 at 11:19 PM by You! for the following reason:

Problem resolved without definite reason.


1 answer: sort voted first

[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.

more ▼

answered Jun 11 '12 at 06:27 PM

Berenger gravatar image

Berenger
11k 12 19 53

...The objects are removed in the hierarchy...

Also, I now see the many misspellings in my question. My internet connection was slowing to a stop... I was lucky to get the question submitted... I'll fix any errors.

Edit: "MainM" 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...

Jun 11 '12 at 07:20 PM You!

Oupsi right, I forgot that part. I changed my answer.

Jun 11 '12 at 07:23 PM Berenger

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...

Jun 11 '12 at 07:33 PM You!

The problem is (seemingly) resolved... I don't know how, but it's okay if it is working!

Thanks, @Berenger

Jun 11 '12 at 11:19 PM You!
(comments are locked)
10|3000 characters needed characters left

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x141
x64
x6

asked: Jun 11 '12 at 05:38 PM

Seen: 277 times

Last Updated: Jun 11 '12 at 11:19 PM