I’m new here, but I have an issue that wastes my time, so I decide to ask.
I expected to have these things to happen
-
1.It’s moving
-
It shoots cube out when left clicking
-
The cube(cloned one) is destroyed when it touches the ground
So, it can move, and can shoot.
but it deletes the cube itself and errors appear(Ya, that destroyed item and I try to access error)
I’m sorry. But I got no choice but to ask, both google and youtube can’t help me.
#pragma strict
var player : GameObject;
var forward : float;
var rotate_H : float;
var rotate_V : float;
var bullet : Rigidbody;
function Start () {}
function Update () {
var move_forward = Input.GetAxis("Vertical") * 5;
GetComponent.<Rigidbody>().AddRelativeForce
(0, 0, move_forward * 10);
rotate_H += Input.GetAxis("Mouse X") * 10;
rotate_V -= Input.GetAxis("Mouse Y") * 10;
if (rotate_V > 50) {rotate_V = 50;};
if (rotate_V < -80) {rotate_V = -80;};
transform.rotation = Quaternion.Euler(rotate_V, rotate_H, 0);
if (Input.GetButtonDown("Fire1")) {
var bullets : Rigidbody;
bullets = Instantiate(bullet, transform.position, transform.rotation);};
bullet.GetComponent.<Rigidbody>().AddRelativeForce(0, 0, 500);
Destroy(bullets.gameObject,2);
}
function OnCollisionEnter (col : Collision) {
if (col.gameObject.name == "Cube") {Destroy(gameObject);}
}