- Home /
Stop the script - problem with myObject's rotation.
Hi,
I would like to ask you for help! I need to stop my script when "myObject" rotation reaches 0 in X,Y and Z axis ( or it'll be close to that value, e.g. +-3 degrees ). Console shows me "Cannot convert 'void' to 'UnityEngine.Transform'.". I know what it means ;) , but I have no idea how to make my script working. Thanks a LOT and sorry for my English! :)
JS
#pragma strict
private var h : float;
private var v : float;
var horozontalSpeed : float = 0.5;
var verticalSpeed : float = 0.5;
var myObject : GameObject;
function Update()
{
if (Input.touchCount == 1)
{
var touch : Touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
h = horozontalSpeed * touch.deltaPosition.x ;
transform.Rotate( 0, h, 0 );
v = verticalSpeed * touch.deltaPosition.y ;
transform.Rotate( -v, 0, 0 );
}
}
var myObjectPos : Transform = transform.Rotate(0, 0, 0);
if (myObjectPos && transform.Rotate != myObjectPos.Rotate)
{
GetComponent(MoveBackRot).enabled = false;
}
}
Answer by Jessespike · Nov 14, 2014 at 06:36 PM
void Rotate() is a function, but you're trying to use it like a property. Try something like this instead:
var myObjectTrans : Transform = transform;
var myObjectPos : Vector3 = transform.position;
var myObjectRot : Quaternion = transform.rotation;
transform.rotation != myObjectPos.rotation
Thank you Jessespike :)
Your comment was very helpful, but at the end I used another code. When in the future someone will have the same problem, the solution is:
if (myObject.transform.localEulerAngles.x < 1 && myObject.transform.localEulerAngles.y < 1 && myObject.transform.localEulerAngles.z < 1){
//do something;
}
Your answer
Follow this Question
Related Questions
Why is my "yield" statement stopping my script? 1 Answer
How to stop animation on trigger? 1 Answer
How to make a script access animations from a child prefab 1 Answer
In game pause menu 2 Answers
fbx animation beats script animation? 2 Answers