Stride Forums Archive

How to accessing to (another) object from some script?

4 posts, 2413 views, 2015-05-28 to 2015-05-28

jamoreno (Jose Andres Moreno Ruiz) 2015-05-28 #1

I’m wondering how to access to an object position from a script attached to other object.

Example

In the RayCasting example, i just want to move a little bit the camera position when a click is made on a cube.

from the RaycastingScript
var camera = Entity.Get() ; // but camera is not an Entity

so I want to do something like this
"camera".transform.position = new Vector3(0,1,0);

How can i do that??

Thank you in advance.

xen2 (Virgile) 2015-05-28 #2

You could add an Entity property to your script:

public Entity Camera { get; set; }

Then, in the editor, you can make set this Camera property to point to a specific entity.
It will then be directly accessible from your script as

Camera.Transform.Position = new Vector3(0, 1, 0);
jamoreno (Jose Andres Moreno Ruiz) 2015-05-28 #3

Yes …! It works very well …!! Thank you very much.
But what i can not understand is the meaning difference between a camera Entity and this
camera = Entity.Get();

jamoreno (Jose Andres Moreno Ruiz) 2015-05-28 #4 in reply to #3

In the same example you also can do:
camera = Entity.Get();
Entity cameraEntity = camera.Entity; //get the entity parent for the component
cameraEntity.Transform.Position = new Vector3 (0,1,0);

So components are “things” belongs to an entity . am I wrong?