I want to make a pokemon lke game, where the player has to recognize the tile he is on.
The error comes from line 96 (if(hit.collider.gameObject.Tag){).
This is the complete Error Log :
InvalidCastException: Cannot cast from source type to destination type.
(wrapper dynamic-method) UnityEngine.RaycastHit.RaycastHit$get_collider$ (object,object)
Boo.Lang.Runtime.RuntimeServices.GetProperty (object,string)
UnityScript.Lang.UnityRuntimeServices.GetProperty (object,string)
Movement.calculateTileOn () (at Assets/scripts/Movement.js:96)
Movement.Update () (at Assets/scripts/Movement.js:29)
This is my script:
var startPoint : Vector3;
var endPoint : Vector3;
var speed : float;
private var increment : float;
var isMoving : boolean;
var tileSpace : float;
var tileOn : String;
var tile : GameObject ;
var tileStatts;
function Start () {
startPoint = transform.position;
endPoint = transform.position;
}
function Update () {
calculateTileOn ();
if(increment <=1 && isMoving == true){
increment += speed/100;
}
else{
isMoving = false;
}
if(isMoving){
transform.position = Vector3.Lerp(startPoint, endPoint, increment);
}
if(Input.GetButton("forward") && isMoving == false){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x, transform.position.y + tileSpace, transform.position.z );
}
if(Input.GetButton("backward") && isMoving == false){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x, transform.position.y - tileSpace, transform.position.z );
}
if(Input.GetButton("left") && isMoving == false){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x - tileSpace, transform.position.y, transform.position.z );
}
if(Input.GetButton("rigth") && isMoving == false){
increment = 0;
isMoving = true;
startPoint = transform.position;
endPoint = new Vector3(transform.position.x + tileSpace, transform.position.y, transform.position.z );
}
}
function calculateTileOn() {
var hit = RaycastHit;
if(Physics.Raycast(transform.position, -Vector3.up)) {
}
if(hit.collider.gameObject.Tag){
tileOn = hit.collider.gameObject.Tag;
tile = GameObject.FindGameObjectsWithTag (tileOn);
tileStatts = tile.Tile;
}
}
And This is my Tiles script:
class Tiles {
var name : String;
var pokemonCount : float;
var walkable : boolean;
var swimable : boolean;
}