hi & thanks for looking at my question.
sp i had the following script i’ve been using that shoots a prefab from the object (right side for reference) the script is attached too. works a treat.
using UnityEngine;
using System.Collections;
public class _BallLauncher : MonoBehaviour {
public Rigidbody projectile;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
void Update() {
if (Input.GetButtonDown("Fire1")&& Time.time > nextFire) {
Rigidbody clone;
clone = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
clone.velocity = transform.TransformDirection(Vector3.forward * 35);
clone.rotation = Quaternion.identity;
clone.tag = "RightMarble";
}
}
}
now what i’d like to do is extend the script to shoot once from the right spot , and take next shot from the left spot and so on. the left spot also has the script attached to it. i have the logic of the script trace out correct ‘true’ and ‘false’ via debug. currently both spawn points shoot at the same time and i would like them to alternate, take turns who shoots. script i have till now is
using UnityEngine;
using System.Collections;
public class _BallLauncher : MonoBehaviour {
public Rigidbody projectile;
public float fireRate = 0.5F;
private float nextFire = 0.0F;
public bool SideSelectLeft = false;
void Update() {
if (Input.GetButtonDown("Fire1")&& Time.time > nextFire) {
if( SideSelectLeft != true){
Debug.Log("SideSelectLeft false:"+SideSelectLeft);
Rigidbody cloneR;
cloneR = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
cloneR.velocity = transform.TransformDirection(Vector3.forward * 35);
cloneR.rotation = Quaternion.identity;
cloneR.tag = "RightMarble";
SideSelectLeft = true;
} else {
Debug.Log("SideSelectLeft true:"+SideSelectLeft);
Rigidbody cloneL;
cloneL = Instantiate(projectile, transform.position, transform.rotation) as Rigidbody;
cloneL.velocity = transform.TransformDirection(Vector3.forward * 35);
cloneL.rotation = Quaternion.identity;
cloneL.tag = "LeftMarble";
SideSelectLeft = false;
}
}
}
}
logically i understand why the script wont work this way, as the prefab is spawning from the point of what the script is attached to. so am i better off attaching the code to an empty gameobject and referencing which spawn point to use next? or can i edit the script to have it working just attached to the two spawn points as it currently is. what the best approach?
sorry for the lengthy explanation.