So basicaly im attempting to accomplish this: Send a ray. Have it hit an object that has the 'theRotator' script attached to it. when the object gets hit call the rotateObject function.
Right now the script is throwing a null on the rotationScript variable, and im really not sure why.
Im using this rotation script: http://answers.unity3d.com/questions/7380/rotate-90-degrees-over-time-with-parabolic-easing
Part of the issue that I know im having is the
rotationScript.RotateObject(otherObj.transform, Vector3.up*-90, .5);
Im sot sure what should be in the otherObj part to call the 'current' object
//Get the RotationHandler Script and call function to execute on ray trigger
var hit : RaycastHit;
function Update () {
var ray : Ray = Camera.main.ScreenPointToRay(Vector3((Screen.width / 2),(Screen.height / 2)));
if (Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) {
if (Physics.Raycast (ray, hit, 10)) {
Debug.DrawLine (ray.origin, hit.point);
print("ray sent");
var otherObj : GameObject = hit.collider.gameObject;
var rotationScript : theRotator = hit.collider.gameObject.GetComponent(theRotator);
var objectName : GameObject = hit.collider.gameObject.name;
print(objectName);
if (rotationScript == null) {
print("rotationScript = null");
}
if (rotationScript != null) {
//appy the LEFT rotation to miniNode & mainNode rotationHandler when left click is pressed
if (Input.GetMouseButtonDown(0)){
rotationScript.RotateObject(otherObj.transform, Vector3.up*-90, .5);
}
//appy the RIGHT rotation to miniNode & mainNode rotationHandler when RIGHT click is pressed
if (Input.GetMouseButtonDown(1)){
rotationScript.RotateObject(otherObj.transform, Vector3.up*90, .5);
}
}
} //End of the Ray if statement
}//End of the Mouse down (0,1) statement
}//End of the Update Function
asked
Apr 27 '10 at 01:05 AM
Ben 4
45
●
5
●
5
●
10