x


Automatically uncheck?

hi, i have a problem with gameobject again. i attach the script in a gameobject, and then i Clone that gameobject, then destroy the original gameobject. my question is Why the script automatically uncheck in cloned gameObject ? and then how can i fix it?? thanks

more ▼

asked Jul 08 '12 at 07:32 PM

m4s4m0r1 gravatar image

m4s4m0r1
122 2 11 20

Could you show us the piece of code that does that?

Jul 09 '12 at 09:03 AM Kryptos

Ugh...i posted an answer to this like 3 hrs ago...I wish my account didnt get screwed up in the move to dev unity wtevr site.

boolean defaults to false..so if you create a new instance of an object that has the same script(unless declared otherwise) it will start out false (regardless of inspector-since the inspecter reference was to the parent and not this clone).

To fix

Simply say that this variable = true upon instantiation

public var myPlayer:Transform;

function ClonePlayer()
{
    var clone=Instantiate(myPlayer,myPlayer.position,myPlayer.rotation);
    clone.GetComponent(MyScript).variable=true;
}
Jul 09 '12 at 09:10 AM OperationDogBird

please dont comment as the answer, so i get notification about a new answer. But, hey thanks OperationDogBird, your answer its true, now my gameobject work properly. Thank you very much

Jul 09 '12 at 09:21 AM m4s4m0r1
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Boolean defaults to false (unchecked) when created. If you dont make that specific boolean true (check) when it is created it assumes the default value of false. You can easily remidy the problem by simply saying something of the sorts

var playerClone=Instantiate(player,position,rotation);
playerClone.GetComponent(MyScript).myVar=true;

notice the variable for the newly instantiated object and then the ref to the actual script that we need to change to get the desired results.

more ▼

answered Jul 09 '12 at 09:55 AM

OperationDogBird gravatar image

OperationDogBird
1.1k 1 8 15

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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:

x3446
x3322
x2077
x764

asked: Jul 08 '12 at 07:32 PM

Seen: 267 times

Last Updated: Jul 09 '12 at 09:55 AM