Hi! I’m going through the introductory tutorials and every time I fire multiple(about10) instances are created . Here is the code from the tutorial as I inputed. Am I missing something? - paul
var newObject : Transform;
function Update () {
if (Input.GetButton(“Fire1”)) {
Instantiate(newObject, transform.position, transform.rotation);
}
Update is called once per frame. If the game is running fast, the mouse will be down for more than one of the frames. You should probably instantiate directly in response to the OnMouseDown or OnMouseUp. It might look something like this:
function OnMouseDown () {
if (Input.GetButton("Fire1")) {
Instantiate(newObject, transform.position, transform.rotation);
}
}
public var newObject : Transform;
public var createRate = 0.5;
private var lastShot = -10.0;
function Update ()
{
if (Input.GetButton("Fire1"))
{
if (Time.time > lastShot + createRate)
{
Instantiate(newObject, transform.position, transform.rotation);
lastShot = Time.time;
}
}
}