Ok so right now i’m working on a selection script and I can’t seem to get a variable in another script work out properly. Before I added the new stuff it worked fine, and I just kept the same thing, but now doesn’t seem to work.
When there is a selected object it should send the pathEnabler to equal true, but it doesn’t seem to be sending, or there is something disabling it that I can’t see.
The place is at 24-27 lines:
using UnityEngine;
using System.Collections;
public class CamSelection : MonoBehaviour {
public GameObject PSselected;
private GameObject PSselectedClone;
public GameObject PSwaiting;
private GameObject PSwaitingClone;
public GameObject PSenemy;
private GameObject PSenemyClone;
private Transform myTransform;
private GameObject cachedObj;
private GameObject objCached;
private GameObject slcObj;
private GameObject enmObj;
// Use this for initialization
void Start () {
myTransform = transform;
}
void Update () {
GetTarget ();
if(slcObj) {
PathMaker pathMaker = slcObj.gameObject.GetComponent<PathMaker>();
pathMaker.pathEnabler = true;
}
if(Input.GetKeyDown(KeyCode.Escape)) {
slcObj = null;
enmObj = null;
}
}
private void GetTarget () {
Ray ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
RaycastHit hit;
if(Physics.Raycast(ray/*Starting Point*/, out hit/*Direction of Ray*/, Mathf.Infinity/*Distance of ray*/)) {
if(hit.collider.tag == "Player1" | hit.collider.tag == "Player2" | hit.collider.tag == "Player3" | hit.collider.tag == "Player4" | hit.collider.tag == "Player5" | hit.collider.tag == "Player6" | hit.collider.tag == "Enemy") {
objCached = hit.collider.gameObject;
if(Input.GetMouseButtonDown(0) hit.collider.tag != "Enemy")
slcObj = objCached;
if(Input.GetMouseButtonDown(0) hit.collider.tag == "Enemy")
enmObj = objCached;
}else{
objCached = null;
}
if(objCached != cachedObj) {
cachedObj = objCached;
}
}
if(cachedObj !Input.GetMouseButton(1) !slcObj !enmObj) {
if(!PSwaitingClone) {
Vector3 bullseye = cachedObj.transform.position;
bullseye.y = cachedObj.transform.position.y-cachedObj.transform.position.y;
PSwaitingClone = Instantiate(PSwaiting, bullseye, Quaternion.identity) as GameObject;
}else{
Vector3 bullseye = cachedObj.transform.position;
bullseye.y = cachedObj.transform.position.y-cachedObj.transform.position.y;
PSwaitingClone.transform.position = (bullseye);
}
}else{
Destroy(PSwaitingClone);
}
if(slcObj) {
if(!PSselectedClone) {
Vector3 bullseye = slcObj.transform.position;
bullseye.y = slcObj.transform.position.y-slcObj.transform.position.y;
PSselectedClone = Instantiate(PSselected, bullseye, Quaternion.identity) as GameObject;
}else{
Vector3 bullseye = slcObj.transform.position;
bullseye.y = slcObj.transform.position.y-slcObj.transform.position.y;
PSselectedClone.transform.position = (bullseye);
}
}else{
Destroy(PSselectedClone);
}
if(enmObj) {
if(!PSenemyClone) {
Vector3 bullseye = enmObj.transform.position;
bullseye.y = enmObj.transform.position.y-enmObj.transform.position.y;
PSenemyClone = Instantiate(PSenemy, bullseye, Quaternion.identity) as GameObject;
}else{
Vector3 bullseye = enmObj.transform.position;
bullseye.y = enmObj.transform.position.y-enmObj.transform.position.y;
PSenemyClone.transform.position = (bullseye);
}
}else{
Destroy(PSenemyClone);
}
}
}
No other scripts in my scene can possibly be disabling it.
(And yes this script is very messy and not very efficient, I just want to get it all working well enough to clean it up.)