Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translation UnityScript to C# : yield & transform.position

I'm actually working to translate a unity project originally in UnityScript to C#. I already have translated a good part of the project, but i'm confronted to some problems :

The first problem is linked with yield :

yield Attack();
yield;

I already replaced all the : yield WaitForSeconds() but I don't know how to replace this.

Secondly another problem with transform.position :

transform.eulerAngles.y += Input.GetAxis("Horizontal") * speedIdleRotate;
transform.position.y = currentHeight;

Throw the error:

UnityEngine.Transform.eulerAngles is not a variable
UnityEngine.Transform.position is not a variable

It's seem that .y is not considered, but in js I'ts working fine. How to deal with that in C#?

like image 301
PokeRwOw Avatar asked May 15 '26 14:05

PokeRwOw


1 Answers

In JS,

yield; // this means that wait for one frame

In C#,

yield return null;

I am not 100% sure but for yield Attack();

It should be

yield return Attack();

For,

transform.eulerAngles.y += Input.GetAxis("Horizontal") * speedIdleRotate;

Try this:

transform.eulerAngles = new Vector3( transform.eulerAngles.x , transform.eulerAngles.y + Input.GetAxis("Horizontal") * speedIdleRotate , transform.eulerAngles.z);

For,

transform.position.y = currentHeight;

Try this:

transform.position =new Vector3(transform.position.x,currentHeight,transform.position.z);

Sorry if I have something wrong.

like image 188
Sreejit Pillai Avatar answered May 17 '26 06:05

Sreejit Pillai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!