- Home /
Question by
Epic-Jargon · Mar 23, 2013 at 08:23 PM ·
collisiongameobjecttag
Collision problem
hi i'm going through a tutorial (http://www.youtube.com/watch?v=75AaGJIeaog) but i'm having problems even though i've followed the tutorial correctly.
heres the code
#pragma strict
var health : int = 100;
var speed : int = 5;
var collided_with = GameObject;
function Start () {
}
function Update () {
if(Input.GetAxis("Horizontal") > 0){
if (collided_with != null){
if (collided_with.tag == "Left"){
return;
}
}
transform.Translate(Vector3(1 * speed * Time.deltaTime, 0, 0));
}
if(Input.GetAxis("Horizontal") < 0){
if (collided_with != null){
if (collided_with.tag == "Right"){
return;
}
}
transform.Translate(Vector3(-1 * speed * Time.deltaTime, 0, 0));
}
}
function OnCollisionEnter(col : Collision){
collided_with = col.gameObject;
}
function OnCollisionExit(col : Collision){
collided_with = null;
}
i have 3 errors they are :
Assets/Scripts/player_Script.js(13,43): BCE0019: 'tag' is not a member of 'System.Type'.
Assets/Scripts/player_Script.js(22,43): BCE0019: 'tag' is not a member of 'System.Type'.
Assets/Scripts/player_Script.js(31,29): BCE0022: Cannot convert 'UnityEngine.GameObject' to 'System.Type'.
any help is appreciated
Comment
Best Answer
Answer by robertbu · Mar 23, 2013 at 08:27 PM
Line 5 should be:
var collided_with : GameObject;
Answer by Epic-Jargon · Mar 23, 2013 at 10:20 PM
thx this worked perfectly, i tried to thumbs up the answer but i dont have permission