x


Ray cast collider recognition and execution of a script attached to hit object

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
more ▼

asked Apr 27 '10 at 01:05 AM

Ben 4 gravatar image

Ben 4
45 5 5 10

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try using hit.collider.gameObject.SendMessage("rotateObject",0.5);

more ▼

answered Apr 27 '10 at 02:39 PM

spinaljack gravatar image

spinaljack
9.1k 18 31 91

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2090
x1703
x1532
x197
x151

asked: Apr 27 '10 at 01:05 AM

Seen: 2673 times

Last Updated: Apr 27 '10 at 01:05 AM