- Home /
Question by
eeveelution8 · Mar 09, 2013 at 03:30 AM ·
gun
gun problems
i have this script, but it works on a older version of unity, anyone know how to fix it?`public var bulletPrefab : Transform; public var BulletSpeed : float = 1000;
public var bulletPrefab : Transform;
public var BulletSpeed : float = 1000;
function Update() {
if (Input.GetButtonDown("Fire1")) {
if (!BulletSpeed || bulletPrefab) {
Debug.Log("Shoot Values undefined");
} else {
var Shot = Instantiate(BulletPrefab, GameObject.find("Spawn Point").transform.position, Quaternion.identity);
Shot.rigidbody.AddForce(UnityEngine.Transform * BulletSpeed);
}
}
}
Comment
Best Answer
Answer by robertbu · Mar 09, 2013 at 03:45 AM
I don't believe this script ever worked no matter how old the Unity version. There were too many problems. Here is a fixed version. Note I changed the fire trigger to GetMouseButtonDown().
public var bulletPrefab : Transform;
public var bulletSpeed : float = 1000;
function Update() {
if (Input.GetMouseButtonDown(0)) {
if (bulletPrefab == null) {
Debug.Log("Shoot Values undefined");
} else {
var Shot = Instantiate(bulletPrefab, GameObject.Find("Spawn Point").transform.position, Quaternion.identity);
Shot.rigidbody.AddForce(transform.forward * bulletSpeed);
}
}
}
Your answer
Follow this Question
Related Questions
How do I put a delay on a gunshot? 2 Answers
Bullet Collision Issues 1 Answer
Reloading A Gun My Way 2 Answers
Particles not appearing on impact, muzzle flash problems? 2 Answers
Weapon random movement 0 Answers