excuse me : Why I cann't run script of C#?

See following
question #1

scripts of javascript:

function Update () {

    GetComponent(Transform).Rotate(0,5,0);
}

Can run…

scripts of C#

using UnityEngine;
using System.Collections;

public class sy01_c_sharp : MonoBehaviour {


	void Start () {
	
	}
	

	

	void Update () {

	
	GetComponent(Transform).Rotate(0,5,0);

	}
}

can’t run…

message : Expression denotes a’type’,where a ‘variable’,‘value’ or ‘method group’ was expected

---------------------------------
question #2

scripts of javascript:

function Start()
{
	
	transform.Translate(0,1.5,0);
	
	}

Can run…

scripts of C#

using UnityEngine;
using System.Collections;

public class sy01_c_sharp : MonoBehaviour {


	void Start () {
	
	  transform.Translate(0 , 1.5 , 0);
	
	}
	

	

	void Update () {

	


	}
}

can’t run…

message : The best overloaded method match for ‘UnityEngine.Transform.Translate(float,float,float)’ has some invalid arguments

Thanks a lot for any help…

1 case: GetComponent expects a type. Types are gathered through typeof()

2 case: 1.5 is no float, thats a double.
It should be 1.5F

o,thank you very much.:smile: :smile:

But again not run too in case #1:

Code is as follows

using UnityEngine;
using System.Collections;

public class sy01_c_sharp : MonoBehaviour {


   void Start () {
   
   }
   

   

   void Update () {

   
   GetComponent(typeof(Transform)).Rotate(0,5,0);   //error

   }
}

message:‘UnityEngine.Component’ does not contain a definition for ‘Rotate’.
:cry: :cry: :cry: :cry: :cry:

well Getcomponent returns a Component, not a Transform.
so you would first need to cast it to Transform

but the solution for the standard components like Transform is simpler:

just use transform.Rotate(…)
on MonoBehaviour extended classes

that will do the same as retrieving the component and casting (its not stored in there as in a field), but it does so invisible behind the scene.

Thank you,I see…

	((Transform)(GetComponent(typeof(Transform)))).Rotate(0,.5f,0);

Really is too cumbersome…
:frowning: :frowning: :frowning:
But I have no choice…

to thank again

:stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue:

just use transform.Rotate(…)

you do not need to use Getcomponent for the default components on game objects like the Transform

:stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: Thank you
But I think Existence that is reasonable,So I would like to continue to research…
After all, I like c# :stuck_out_tongue: :stuck_out_tongue: :stuck_out_tongue: