Hi all,
I’m having problems displaying a variable in my OnCollsionEnter() function.
I have created a datamanager class to hold all my variables so I can retrieve them from any script:
using UnityEngine;
using System.Collections;
// This script holds any data that is to be passed from script to script
public class dataManager
{
private Vector3 d_lightPos, d_cubePos;
private GameObject d_Grid;
private short d_Count;
private int d_Lights;
private ArrayList obsPos = new ArrayList();
private ArrayList lgtPos = new ArrayList();
public void setCubePosition(Vector3 cubePos)
{
d_cubePos = cubePos;
}
public Vector3 getCubePosition()
{
return d_cubePos;
}
public void setLightPosition(Vector3 lightPos)
{
d_lightPos = lightPos;
}
public Vector3 getLightPosition()
{
return d_lightPos;
}
public void setGridPiece(GameObject p_Grid)
{
if (p_Grid == null)
{
p_Grid = new GameObject();
}
else
{
d_Grid = p_Grid;
}
}
public GameObject getGridPiece()
{
return d_Grid;
}
public void setObstacleCount(short p_Count)
{
d_Count = p_Count;
}
public short getObstacleCount()
{
return d_Count;
}
public void setLightsOnCount(int p_Count)
{
d_Lights = p_Count;
}
public int getLightsOnCount()
{
return d_Lights;
}
public void setObstaclePosition(Vector3 d_Pos)
{
if (d_Pos == Vector3.zero)
{
d_Pos = new Vector3(0,0,0);
obsPos.Add(d_Pos);
}
else
{
obsPos.Add(d_Pos);
}
}
public Vector3 getObstaclePosition(short index)
{
return (Vector3)obsPos[index];
}
public void setLightPositionList(Vector3 d_Pos)
{
if (d_Pos == Vector3.zero)
{
d_Pos = new Vector3(0,0,0);
lgtPos.Add(d_Pos);
}
else
{
lgtPos.Add(d_Pos);
}
}
public Vector3 getLightPositionList(short index)
{
return (Vector3)lgtPos[index];
}
}
And in my cubecollider class I call the functions I need:
using UnityEngine;
using System.Collections;
public class cubeCollider : MonoBehaviour
{
private enum sides{down, up, back, front, left, right};
Vector3 cubePos, lightPos;
Transform temp;
sides checkSides;
dataManager m_DataManager;
void Start()
{
m_DataManager = new dataManager();
cubePos = m_DataManager.getCubePosition();
lightPos = m_DataManager.getLightPosition();
}
void OnCollisionEnter(Collision collision)
{
Debug.Log("Cube:" + cubePos);
Debug.Log("Light: " + lightPos);
}
}
They are being correctly set in other scripts. Im completely confused as to how these variables only show (0,0,0), yet if I Debug them in the datamanager class before they are returned I get the correct values. What am I doing wrong?