Hi everyone i am having some trouble with my scripts communication the script i link should change a variable in an other script when the player stay for 2 second on a platform everything work and no error but the variable that should get change never really change so everything outside the script doesn’t work any idea why ?
this is the two script first the one that should change the var on the other script called Platform the tochingPlatform variables is set in editor for every platform that has the script attached
thanks for the help i am going crazy everything work no error but can’t find the logic that doesn’t change the variable
List item
using UnityEngine;
using System.Collections;
public class ShiStayRespawn : MonoBehaviour {
public int touchingPlatform;
public GameObject respawnController;
public CheckPoint checkPoint;
// Use this for initialization
void Start () {
respawnController = GameObject.Find("RespawnController");
checkPoint = respawnController.GetComponent<CheckPoint>();
}
void OnTriggerEnter(Collider col)
{
checkPoint.starTimer = Time.time;
checkPoint.nextTimer = checkPoint.starTimer + 2;
}
void OnTriggerStay(Collider col)
{
if(col.gameObject.CompareTag("Player"))
{
checkPoint.starTimer = Time.time;
if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 0)
{
Debug.Log("Start");
checkPoint.Platform = 0;
Debug.Log("Last Check : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
}
if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 1)
{
Debug.Log("1");
checkPoint.Platform = 1;
checkPoint.saveState = 2;
Debug.Log("Last Check 2222222 : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
}
if (checkPoint.starTimer >= checkPoint.nextTimer && touchingPlatform == 2)
{
Debug.Log("End");
//checkPoint.lastCheckPoint = checkPoint.checkPoints[2].transform.position;
checkPoint.Platform = 2;
checkPoint.saveState = 3;
Debug.Log("Last Check 3333333 : " + checkPoint.lastCheckPoint.ToString() + "Touchin " + touchingPlatform.ToString());
}
}
}
public void OnTriggerExit(Collider other)
{
Debug.Log(checkPoint.lastCheckPoint.ToString());
//checkPoint.Platform = touchingPlatform;
}
}
and this is the script that should received the change value
using UnityEngine;
using System.Collections;
public class CheckPoint : MonoBehaviour {
public Vector3 lastCheckPoint ;
public int saveState;
public float starTimer;
public float nextTimer;
public GameObject[] checkPoints = new GameObject[3];
public GameObject[] lightsPlatform = new GameObject[5];
public int Platform = 0;
// Use this for initialization
void Start ()
{
checkPoints[0] = GameObject.Find("TheStart");
checkPoints[1] = GameObject.Find("Check1");
checkPoints[2] = GameObject.Find("TheEnd");
saveState = 1;
AssignCheckPoint(Platform);
}
void Update()
{
AssignCheckPoint(Platform);
}
public void AssignCheckPoint(int other)
{
lastCheckPoint = checkPoints[other].transform.position;
}
}