- Home /
pubblic variable don't get change from script with OnTriggerStay
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;
}
}
Answer by tango209 · Feb 12, 2015 at 06:05 AM
That code works fine. Are any debug messages coming through?
Put a Debug.Log in the OnTriggerEnter to make sure it's getting hit.
Make sure you tagged the 'Player'.
Make sure at least one of the objects has a rigidbody. Maker sure IsTrigger is checked in the colliders.
that's the strange thing no debug messages at all , seems all to work fine even the debug messages works fine but if you look at the inspector while playing none of the variable involved get changed and when i make breakpoints in visual studio to debug all seems to work fine oh well i thought was some error in this code that i didn't see but it seems is fine then i will try debug all logic and see where it get lost thanks for look at the code and for thw answer tango209