简体   繁体   中英

How do I use a variable after a transform

I'm using unity so this is all unity

For example if I have string direction = left;

I want to do transform.left; as transform.direction;

It throws an error when I do this cause transforms font have direction as one of those things after the dot.

Use a Vector3 for direction and you can just use transform.TransformDirection for this:

Vector3 direction = Vector3.left;
Vector3 worldDirection = transform.TransformDirection(direction);

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