Input.GetMouseButtonDown not working in Play mode
Hi! I don't know why Input.GetMouseButtonDown(0) not working in Play mode, but if i build&run - it's works good.
Why? This is my code:
using UnityEngine;
using System.Collections;
public class Spawner : MonoBehaviour {
public static Spawner Instance { get; private set; }
public GameObject area;
public GameObject enemy;
public GameObject player;
public float scaleX, scaleY, startPoint, minY, maxY;
public bool gameRunning;
public float enemyDefaultSize = 0.2F;
void Awake() {
gameRunning = true;
Instance = this;
}
void Start () {
scaleX = area.transform.localScale.x;
scaleY = area.transform.localScale.y;
startPoint = scaleX / 2;
minY = (-area.transform.localScale.y / 2)+0.2F;
maxY = (area.transform.localScale.y / 2)-0.2F;
CallEnemy ();
spawnPlayer ();
}
void spawnPlayer(Vector3 pos = default(Vector3)) {
float spawnPlayerPoint = (scaleX / 2)/2;
float startY = Random.Range (minY, maxY);
player.GetComponent<Player> ().damage = 20;
player.GetComponent<Player> ().fireDelaySet = 1.0F;
if(pos == Vector3.zero) Instantiate (player, new Vector3(-spawnPlayerPoint, startY, -1), Quaternion.identity);
else Instantiate (player, new Vector3(pos.x, pos.y, -1), Quaternion.identity);
}
public void CallEnemy() {
float startY = Random.Range (minY, maxY);
Instantiate (enemy, new Vector3(startPoint, startY, -1), Quaternion.identity);
enemy.name = "Bot";
}
void Update () {
if (gameRunning) {
Debug.Log ("Test message");
if (Input.GetMouseButtonDown (0)) {
Debug.Log ("Clicked!");
spawnPlayer (); //Work in Build&Play, but not in Editor(Play mode)
}
}
}
}
Comment
how far do you get with your debugs?
btw. there's Application.isPlaying if you need that
http://docs.unity3d.com/ScriptReference/Application-isPlaying.html