- Home /
Question by
MadJohny · May 10, 2013 at 02:33 PM ·
javascripterrorerror messageerror-handling
Error, I have no idea why :(
I'm getting this error,
"InvalidCastException: Cannot cast from source type to destination type.
Player.Update () (at Assets/Mine/Scripts/Player.js:30)"
but I don't know what it means or why it's happenning. this is my script:
#pragma strict
var range : float;
var bombs : int = 1;
var speed : int = 1;
var fire : int = 1;
var bomb : Transform;
var bombSpawner : GameObject;
var health : int = 1;
var Distance : float;
var MaxDistance : float = 1.6;
function Update ()
{
MaxStats ();
Speed ();
if (health < 1)
Destroy (gameObject);
Debug.DrawRay(transform.position, (transform.forward + Vector3.down).normalized * range, Color.red);
if (Input.GetMouseButtonDown(0) && bombs >=1)
{
var Hit : RaycastHit;
if (Physics.Raycast(transform.position, (transform.forward + Vector3.down).normalized , Hit, range))
{
if(Hit.collider.gameObject.tag == "Ground")
{
var bomb : Transform = Instantiate (bomb, Hit.collider.gameObject.transform.position, Quaternion.identity);
bomb.gameObject.transform.Translate(0,0.77,0);
}
}
}
}
Comment
Best Answer
Answer by MadJohny · May 11, 2013 at 01:21 PM
I changed the bomb var to GameObject instead of Transform, now it's working properly
Answer by ryba · May 10, 2013 at 03:07 PM
Change line 30 and 31 to:
var bombInstance : Transform = Instantiate (bomb, Hit.collider.gameObject.transform.position, Quaternion.identity);
bombInstance.gameObject.transform.Translate(0,0.77,0);
Your answer
Follow this Question
Related Questions
Lots of errors after importing john lemon's haunted jaunt package from asset store 0 Answers
Cannot Open Javascript in MonoDevelop 1 Answer
InvalidCastException: Cannot cast from source type to destination type. 1 Answer
Why are these errors messing with me? 2 Answers
';' expected. Insert a semicolon at the end. I already have a ; 1 Answer