Change a Transform in Runtime?

This is driving me insane!

How can I change the targeted transform/object in Runtime, if I need to switch targets. Nothing I seem to try will assign a target at runtime :frowning:

355931--12373--$transform_192.jpg

And what do you assign in run time ? A GameObject ? Or a Transform ?

You have a variable of type Transform, you can’t store a value of type GameObject in there.

assignements you do at runtime will be reverted once you leave the play mode.
you need to do them at non-play time.

also in the game you would do the switch target through scripting.

The Object, as I’m guessing the transform will just come as part of it?[/quote]

It’s simple. The variable type is Transform, so it wants a Transform component.

When you write GameObject.Find (“object name”), you retrieve a GameObject.

var foo : Transform;
// Won't work.
foo = GameObject.Find ("object name");

You can’t still assign it yet. You must get the Transform component. How ? transform.

var foo : Transform;
// Should work
foo = GameObject.Find ("object name").transform;

AkilaeTribe! Thanks!! :smile: :smile: :smile:

I had indeed tried what you said previous to your post, but I wasn’t using a second var i.e “foo” with a secondary Transform. Now its works Perfectly!

Thank you so much this has been driving me nuts all day :slight_smile:

:lol: thank you perfectly works.

That worked perfectly, thanks!!!