OK. I have a script that shoots a raycast if you press than release the left mouse button, if you hold it down, it charges up a chargedShot instead. I have a timer function that activates the charging function at the right time, but when you let go of the mouse button after charging I want it to fire.
here’s the code so far,
public Rigidbody chargedShot;
public float chargedShotSpeed;
public GameObject dummy;
void Update(){
if(timerstart){
timer += Time.deltaTime;
}
if (Input.GetMouseButtonDown(0)){
startCount = Time.time;
timerstart = true;
}
if(timer >= waitTime Input.GetMouseButton(0)){
Charging();
timer = 0;
timerstart = false;
}
if(Input.GetMouseButtonUp(0)){
stopCount =Time.time;
elapsedTime = stopCount - startCount;
if(elapsedTime <=.49){
timer = 0;
timerstart = false;
Fire();
audio.Play();
animation.Play("smallRecoil");
}
}
}
void Charging(){
Rigidbody chargedShotClone = Instantiate (chargedShot, dummy.transform.position, dummy.transform.rotation) as Rigidbody;
chargedShotClone.transform.parent = transform;
if(Input.GetMouseButtonUp(0)){
chargedShotClone.velocity = transform.TransformDirection(Vector3(0, 0, chargedShotSpeed));
chargedShotClone.transform.parent = null;
}
}
the dummy is just a non-rendered cube sitting in front of the characters hand where I want the chargedShot to materialize. It shows up fine, but it won’t:
a)fire when the mouse button is released.
Error:Expression denotes a type', where a variable’, value' or method group’ was expected
b)it becomes unparented from my character’s movement, but it still moves with the mouse cursor.
HELP PLEASE, been working on this for 2 days.