//why isn’t collided_with working?
var health : int = 100;
var speed : int = 5;
var laser_pref : Transform;
var firerate : float = 0.4;
var nextshot : float = 0.0;
function Start () {
}
function Update () {
}
if(Input.GetAxis("Horizontal") > 0){
if (collided_with != null){
if (collided_with.tag == "Left"){
return;
}
}
transform.Translate(Vector3(2 * speed * Time.deltaTime,0,0));
}
if(Input.GetAxis("Horizontal") < 0){
if (collided_with != null){
if (collided_with.tag == "Right"){
return;
}
}
transform.Translate(Vector3(-2 * speed * Time.deltaTime,0,0));
}
if(Input.GetAxis("Vertical") > 0){
if (collided_with != null){
if (collided_with.tag == "Up"){
return;
}
}
transform.Translate(Vector3(0,1 * speed * Time.deltaTime,0));
}
if(Input.GetAxis("Vertical") < 0){
if (collided_with != null){
if (collided_with.tag == "Down"){
return;
}
}
transform.Translate(Vector3(0,-2 * speed * Time.deltaTime,0));
}
if(Input.GetAxis("FireLaser")){
if (Time.time >= nextshot){
Instantiate(laser_pref, Vector3(transform.position.x, transform.position.y +1.5, 2), Quaternion.identity);
nextshot = Time.time + firerate;
}
}
function OnCollisionEnter(col : Collision){
collided_with = col.gameObject;
if (col.gameObject.tag == "enemy"){
Destroy(col.gameObject);
Destroy(gameObject);
}
}
function OncollisionExit(col : Collision){
col_with = null;
}