Hi guys,
the game I am woring on has two functions so far: Opening a menu by pressing space and instantiating objects when UI-buttons in the menu are pressed. The script for the menu animation is on the FPS and the scripts for spawning the objects are on an empty game object.
The problem is that when I use the spacebar to open or close the menu it now also spawns objects, even though I didn’t press any buttons. This only happens once I pressed a button, not when no buttons were pressed during a testrun.
I don’t really see why this happens or where the connection between the spacebar and the buttons is.
Here is the scipt for the menu:
using UnityEngine;
using System.Collections;
public class MenuAnimS : MonoBehaviour {
bool MenuOpen;
Animator animator1;
void Start () {
animator1 = GameObject.Find("Canvas").GetComponent<Animator>();
animator1.enabled = false;
MenuOpen = false;
}
void Update () {
if (Input.GetKeyUp ("space") && MenuOpen == false) {
animator1.enabled = true;
animator1.Play ("MenueAnim");
MenuOpen = true;
} else if (Input.GetKeyUp("space") && MenuOpen == true){
animator1.Play ("MenueAnim2");
MenuOpen = false;
}
}
}
and this is the script for the buttons:
using UnityEngine;
using System.Collections;
public class SR : MonoBehaviour {
private GameObject objCamera;
private Vector3 SpawnPosition;
private int DistanceToCamera = 5;
public Transform creation;
public Transform player;
void Start () {
objCamera = (GameObject) GameObject.FindWithTag("MainCamera");
}
public void Spwn () {
SpawnPosition = objCamera.transform.forward * DistanceToCamera + objCamera.transform.position ;
Instantiate(creation, SpawnPosition, player.transform.rotation);
}
}
Does anyone see what I’ve missed?
Thanks