Drag/rotate/throw script errors?

Hey I’m getting errors with this script and was wondering if anyone could solve it for me?

Errors:

BCE0019: ‘sensitivityX’ is not a member of ‘UnityEngine.Component’.
BCE0019: ‘sensitivityY’ is not a member of ‘UnityEngine.Component’.
BCE0019: ‘ScreenPointToRay’ is not a member of ‘UnityEngine.Component’.
BCE0005: Unknown identifier: ‘body’.
BCE0005: Unknown identifier: ‘oldYRotCam’.
BCE0005: Unknown identifier: ‘oldYRotObj’.
BCE0005: Unknown identifier: ‘oldYRotComp’.
BCE0005: Unknown identifier: ‘newYRotCam’.
BCE0005: Unknown identifier: ‘newYRot’.
BCE0019: ‘ScreenPointToRay’ is not a member of ‘UnityEngine.Component’.
BCE0005: Unknown identifier: ‘horzRot’.
BCE0019: ‘sensitivityX’ is not a member of ‘UnityEngine.Component’.
BCE0019: ‘sensitivityY’ is not a member of ‘UnityEngine.Component’.
BCE0005: Unknown identifier: ‘vertAxis’.
BCE0005: Unknown identifier: ‘horzAxis’.
BCE0005: Unknown identifier: ‘held’.


Script:

var player : GameObject;
var playcam : GameObject;
var grabbed : Transform;
var spring = 50.0;
var damper = 5.0;
var drag = 10.0;
var angularDrag = 5.0;
var distance = 0.2;
var attachToCenterOfMass = false;
var speed = 0.2;
var throwForce : float;
var throwRange : float;
var oldSensY = 15;
var oldSensX = 15;
var rotate : float;
private var vertRotAxis : Vector3;
private var horizontalRot : float;
private var verticalRot : float;
private var springJoint : SpringJoint;
function Start ()
{
}
function Update ()
{
rotate = Input.GetAxis("Rotate");
// Make sure the user pressed the mouse down
if (!Input.GetMouseButtonDown (0))
return;
if (!Input.GetMouseButtonDown (0))
{
Camera.main.GetComponent("MouseLook").sensitivityX = oldSensX;
Camera.main.GetComponent("MouseLook").sensitivityY = oldSensY;
}
Screen.lockCursor = true;
var mainCamera = FindCamera();
// We need to actually hit an object
var hit : RaycastHit;
if (!Physics.Raycast(mainCamera.ScreenPointToRay(Input.mousePosition), hit, 4))
return;
// We need to hit a rigidbody that is not kinematic
if (!hit.rigidbody || hit.rigidbody.isKinematic)
return;
if (!springJoint)
{
var go = new GameObject("Rigidbody dragger");
body = go.AddComponent ("Rigidbody");
springJoint = go.AddComponent ("SpringJoint");
body.isKinematic = true;
}
springJoint.transform.position = hit.point;
if (attachToCenterOfMass)
{
var anchor = transform.TransformDirection(hit.rigidbody.centerOfMass) + hit.rigidbody.transform.position;
anchor = springJoint.transform.InverseTransformPoint(anchor);
springJoint.anchor = anchor;
}
else
{
springJoint.anchor = Vector3.zero;
}
springJoint.spring = spring;
springJoint.damper = damper;
springJoint.maxDistance = distance;
springJoint.connectedBody = hit.rigidbody;
StartCoroutine ("DragObject", hit.distance);
}
function DragObject (distance : float)
{
var oldDrag = springJoint.connectedBody.drag;
var oldAngularDrag = springJoint.connectedBody.angularDrag;
springJoint.connectedBody.drag = drag;
springJoint.connectedBody.angularDrag = angularDrag;
var mainCamera = FindCamera();
grabbed = springJoint.connectedBody.transform;
oldYRotCam = mainCamera.transform.eulerAngles.y;
oldYRotObj = springJoint.connectedBody.transform.eulerAngles.y;
oldYRotComp = oldYRotCam - oldYRotObj;
while (Input.GetMouseButton (0))
{
newYRotCam = mainCamera.transform.eulerAngles.y;
newYRot = newYRotCam - oldYRotComp;
var ray = mainCamera.ScreenPointToRay (Input.mousePosition);
springJoint.transform.position = ray.GetPoint(distance);
Physics.IgnoreCollision(player.collider, grabbed.collider);
yield;
if (Input.GetAxis("Rotate") == 0)
{
horzRot = springJoint.connectedBody.transform.InverseTransformDirection(Vector3.up).normalized;
springJoint.connectedBody.transform.Rotate(horzRot, Input.GetAxis("Mouse X") * 15);
}
if (distance > 5)
{
distance = 5;
}
if (distance < 2)
{
distance = 2;
}
if (Input.GetAxis("Mouse ScrollWheel") > 0 && distance <= 5)
{
distance += speed;
}
if (Input.GetAxis("Mouse ScrollWheel") < 0 && distance >= 2)
{
distance -= speed;
}
if (Input.GetAxis("Rotate") == 0)
{
mainCamera.GetComponent("MouseLook").sensitivityX = oldSensX;
mainCamera.GetComponent("MouseLook").sensitivityY = oldSensY;
player.GetComponent("MouseLook").sensitivityX = oldSensX;
}
if (Input.GetAxis("Rotate") != 0)
{
player.GetComponent("MouseLook").sensitivityX = 0F;
Camera.main.GetComponent("MouseLook").sensitivityX = 0F;
Camera.main.GetComponent("MouseLook").sensitivityY = 0F;
vertAxis = springJoint.connectedBody.transform.InverseTransformDirection(mainCamera.transform.TransformDirection(Vector3.right)).normalized;
springJoint.connectedBody.transform.Rotate(vertAxis, Input.GetAxis("Mouse Y") * 6);
horzAxis = springJoint.connectedBody.transform.InverseTransformDirection(mainCamera.transform.TransformDirection(Vector3.up)).normalized;
springJoint.connectedBody.transform.Rotate(horzAxis, -Input.GetAxis("Mouse X") * 6);
oldYRotCam = mainCamera.transform.eulerAngles.y;
oldYRotObj = springJoint.connectedBody.transform.eulerAngles.y;
oldYRotComp = oldYRotCam - oldYRotObj;
}
if (Input.GetMouseButtonDown (1))
{
held = 0;
Physics.IgnoreCollision(player.collider, grabbed.collider, false);
grabbed = null;
mainCamera.GetComponent("MouseLook").sensitivityX = oldSensX;
mainCamera.GetComponent("MouseLook").sensitivityY = oldSensY;
player.GetComponent("MouseLook").sensitivityX = oldSensX;
springJoint.connectedBody.AddExplosionForce(throwForce,mainCamera.transform.position,throwRange);
springJoint.connectedBody.drag = oldDrag;
springJoint.connectedBody.angularDrag = oldAngularDrag;
springJoint.connectedBody = null;
StopCoroutine ("DragObject");
yield;
}
}
if (springJoint.connectedBody)
{
Physics.IgnoreCollision(player.collider, grabbed.collider, false);
grabbed = null;
springJoint.connectedBody.drag = oldDrag;
springJoint.connectedBody.angularDrag = oldAngularDrag;
springJoint.connectedBody = null;
}
}
function FindCamera ()
{
if (camera)
return camera;
else
return Camera.main;
}

yikes my eyes!! :hushed:, use [code ][/code ] tags when you paste code into the forums, only way a wall like that is going to be readable. There is a sticky on them at the top of the scripting forum

Sorry my bad.
Fix it…it was extremely stupid.
I had the #Pragma Strict still at the top so i removed it and it works fine

that’s not fixing the problem, that’s telling it to not tell you about the problems…

for the errors: “… is not a member of ‘UnityEngine.Component’.”

these stem from using the GetComponent(“…”) without casting the return type. Try using GetComponent.<…>() instead, it’ll retain the type.

for the “Unknown identifiers…” errors, you’re not declaring variables correctly for them

body = ... 

//should be 

var body = ...

Should this be done on all parts highlighted in quotations?
It just wont pick up a rigidbody…

I’m at the point where i can run it but i’m receiving this in the console.

NullReferenceException: Object reference not set to an instance of an object

Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.String cacheKeyName, System.Type[ ] cacheKeyTypes,

Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)

Boo.Lang.Runtime.RuntimeServices.GetDispatcher (System.Object target, System.Object[ ] args, System.String cacheKeyName,

Boo.Lang.Runtime.DynamicDispatching.DispatcherFactory factory)

Boo.Lang.Runtime.RuntimeServices.SetProperty (System.Object target, System.String name, System.Object value)

balthrowgrabro+$DragObject$355+$.MoveNext () (at Assets/G/Resources/Scripts /balthrowgrabro.js:130)

This is caused by trying to use something that doesnt exist. Goto line 130 in the balthrowgrabro.js and make sure that whatever you are trying to access is not null.

I think i’ll leave it, it’s a bit beyond me.

it’s supposed to be able to pick up any rigid body.

thanks for the help guys :slight_smile:
if use figure it out let me know. :slight_smile: