system
1
I keep getting this error and I haven't a clue as to why; other than it has to do with this script. Please help me understand why this is happening
var Player : Transform;
var rotateAmount = 90;
var controller : CharacterController;
var Hit : RaycastHit;
function Start(){
}
function FixedUpdate (){
//casts a ray from camera to point in world
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
// If the controller is grounded and the ray hits an object; then you can Rotate walls
if ((controller.isGrounded) && (Physics.Raycast (ray, Hit, 50))) {
canRotate =true;
var Hitobject : GameObject = Hit.transform.gameObject && Hit.collider;
var pivot : Transform = Hitobject.transform;
if (Hitobject.tag == "Left"){
if(Input.GetMouseButtonDown(0))
RotateObjectForward(Player.position,pivot.forward, 90,1);
if(Input.GetMouseButtonDown(1))
RotateObjectForward(Player.position,-pivot.forward,90,1);
}
}
I'm not certain that is all there is to it but :
var Hitobject : GameObject = Hit.transform.gameObject && Hit.collider;
should probably be:
var Hitobject : GameObject = Hit.transform.gameObject;
A "Cannot cast from source to destination type" is well... an invalid-cast error. In other words, you're trying to reference an incorrect type into a type-restricted variable.
For examples:
var number:int = "ThisIsNotAnInt";
var gameObject:GameObject = 9000;
var custom:MyCustomType = "NotMyCustomType";
would - I believe - all throw the exception. Note that JScript allow for dynamic casting, such as:
var unrestrictedType = "ICanJustReferenceWhateverTypeIWantHere";
var unrestrictedType = 1337;
var unrestrictedType = 3.1415926535;
would - I believe - never throw the exception, though errors might arise later.