Hi, i have a simple first person shooter, and i have a gun which creates projectiles. the projectiles should be moving to an empty in front of it, but instead are moving to a single spot. Can anyone see anything wrong:
using UnityEngine;
using System.Collections;
public class WeaponHold : MonoBehaviour {
public GameObject lefthand;
public GameObject righthand;
public GameObject parent;
public GameObject pump;
public GameObject handle;
public GameObject projectile;
public GameObject lookdirection;
public float pumpspeed;
private bool isPumping;
private bool isReverse;
private float progress;
void Start () {
isPumping = false;
isReverse = false;
}
void Update () {
if (Input.GetKeyDown (KeyCode.Mouse0) && !isPumping) {
int i = 0;
while (i < 10){
Instantiate(projectile);
projectile.transform.position = this.gameObject.transform.position;
i++;
}
isPumping = true;
progress = 1;
}
lefthand.transform.position = pump.gameObject.transform.position;
righthand.transform.position = handle.gameObject.transform.position;
lefthand.transform.LookAt (pump.transform.position);
righthand.transform.LookAt (handle.transform.position);
if (isPumping) {
if (!isReverse) {
pump.transform.Translate (0,(float) -0.1, 0);
progress = progress - (float) 0.1;
if (progress < 0) {
isReverse = true;
progress = 1;
}
}
if (isReverse) {
pump.transform.Translate (0,(float) 0.1, 0);
progress = progress - (float) 0.1;
if (progress < 0) {
isReverse = false;
isPumping = false;
}
}
}
}
}
using UnityEngine;
using System.Collections;
public class ProjectileScript : MonoBehaviour {
public GameObject lookdirection;
void Start () {
this.gameObject.transform.LookAt (lookdirection.transform.position);
this.gameObject.transform.Rotate (0, 90, -270);
}
void Update () {
this.gameObject.transform.Translate (0,(float) 0.1, 0);
}
}
Here’s a screenshot of the error:
I have selected the transform where it should be travelling to
