I was making this turn based game and I was trying to make a script for a button called attack which would tell the player object move = true when clicked. The player script is attached to the player object(obviously) which would get the message from the attack button and use move = true to move the player right. The problem is that the player isn’t moving at all.
script for attack button:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Attack : MonoBehaviour {
public static bool move;
private void OnMouseDown()
{
Debug.Log("Attack Script: true");
move = true;
StartCoroutine(wait());
Debug.Log("Attack Script: false");
move = false;
}
IEnumerator wait()
{
yield return new WaitForSeconds(5);
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
}
script for player:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : MonoBehaviour {
private static bool movement;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
movement = Attack.move;
Debug.Log(movement);
if(movement == true)
{
transform.Translate(Vector2.right * 5f * Time.deltaTime);
}
}
}