EDIT:
I’ve realized this is system wide after pressed any key - I’ve not used this laptop for anything where I’d notice this. Not a unity problem, I’ll find the answer somewhere.
Hi guys,
I’m writing a script to cast spells.
The script switches between casting mode and non-casting mode, creates a sprite which follows the mouse if casting mode is active and destroys the sprite if casting mode is left, and casts a spell if the mouse is clicked while casting mode is active (casting the spell also leaves casting mode).
All seems to be working fine, except after entering casting mode there is a delay of 1-2 seconds before the script will register a mouse click. There is no problem clicking outside of casting mode (as reported by debug.log).
What could be causing this problem? Is it an efficiency problem of some kind?
Code is below. Thanks!
using UnityEngine;
using System.Collections;
public class AbilityUsage : MonoBehaviour {
private bool casting;
public GameObject castingsprite;
public GameObject fireball;
private GameObject castingspriteinstance;
// Use this for initialization
void Start () {
casting = false;
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown ("q"))
{
casting = !casting;
Debug.Log (casting);
if (casting) {
castingspriteinstance = Instantiate (castingsprite, transform.position, transform.rotation) as GameObject;
} else
{
Destroy (castingspriteinstance);
}
}
if (casting) {
Vector3 castingspriteloc;
castingspriteloc = Camera.main.ScreenToWorldPoint (Input.mousePosition);
castingspriteloc = new Vector3 (castingspriteloc.x, castingspriteloc.y, 0);
castingspriteinstance.transform.position = castingspriteloc;
}
if (Input.GetMouseButtonDown (0))
{
Debug.Log ("got the click");
if (casting) {
Debug.Log ("You are casting AND clicked. Have I cast?");
GameObject fireballinstance;
fireballinstance = Instantiate (fireball, transform.position, transform.rotation) as GameObject;
Destroy (castingspriteinstance);
casting = false;
}
}
}
}