简体   繁体   中英

Unity transform an object to a local Vector3 not global

So I want to instanstiate an object and update its position from what where I am spawning it. I am spawning this object on the parets + 10x position.

Instantiate(gameObject, transform.position + new Vector3(10, 0, 0), Quaternion.identity);

When I do this, it nearly does what I want it to, however it will spawn the object and give it 10x on the global position not local, where it was spawned from. After looking online, I tried:

transform.localposition 

However that gave me the error of "CS1061: 'Transform' does not contain a definition for 'localpositon'"

Would anyone know what I am missing when it comes to instanstiating something on a local Vector3?

Edit * Thinking of the terminology, I guess the result that I am expecting is for the object I am creating to be pivoted around a certain point when spawned in, not just rotated and position on the Vector3 coordinates.

This point being the spawn location in the world, which is just parent world location + child location.

When a name does not work try to use auto complete (visual studio) or verify with the Unity docs that it is spelled correctly and that it exists.

The field you seek is called localPosition ( P is capital).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM