Hey guys im actually writing a Java Script on how to making my main character to rotate in the center of the screen, but this compiled error shown up and prevent me from doing that.
Can you guys see what’s the problem? Thank you.!
First, your code in an image is super annoying, anyways.
You have a function(which looks like c#) in your Update function in the If statement.
You should move that out of that scope, replace void with function.
#pragma strict
var rotateLeftKey : KeyCode;
var rotateRightKey : KeyCode;
var rotateSpeed : float = 10;
function Update()
{
// This has a typo in it, you were missing a "t" in right
if (Input.GetKey(rotateRightkey))
{
rotateRight();
GetComponent.<RigidBody2D>().velocity.x = rotateSpeed;
}
else if (Input.GetKey(rotateLeftKey))
{
rotateLeft();
GetComponent.<RigidBody2D>().velocity.x = rotateSpeed * -1;
}
else
{
GetComponent.<RigidBody2D>().velocity.x = 0;
}
// now remove your function here and move it out of the update function scope
}
function rotateRight()
{
transform.Rotate(Vector3.forward * 90);
}
Winner winner chicken dinner.
Don’t forget to include your rotateLeft function too.