I have a script on my player object that sets a bool named “charge” to true when I click on it. This is a precondition to moving my player somewhere else in the play area which is determined by where I click next.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCharge : MonoBehaviour {
private bool charged;
// Use this for initialization
void Start () {
charged = false;
}
void Update ()
{
//Makes the player spin after it gets charged up
// if (charged !=false) {
// transform.Rotate (0,0,1440*Time.deltaTime); //rotates 50 degrees per second around z axis
// }
}
// Click the player to set charge it up
void OnMouseDown () {
if (charged != true) {
charged = true;
// chargedSpin ();
Debug.Log ("Charged Up!");
}
else Debug.Log ("already");
}
}
This first part works, but now I want to:
Create a new script on the background sprite that captures my click and stores the transform info for where I clicked, then, if my player object has the charge = true state, instantly place my player at the position I clicked.
I’m having trouble with the approach - would I be right to put that script on the background sprite? if so, how can I
a) get the variable from my player script and
b) move my player object using this script.
I’ve tried looking into how to get scripts to communicate with each other but I’m having no joy.