- Home /
Click&Drag Misterious Disappearing!
Hi, I created a panel which can be clicked on and dragged (only if click is hitting collider). Thing is it works, but after not even 3 seconds of initiating the game every part of the panel disappears but 1, which is just a background plane for the text. It's really weird, first I thought of the problem being the hit distance, and the panel going too far from the GUI cam, but if it did that, that last panel that survives would go away with it, because I'm affecting a parent object.
On click(0) and maintain on the collider, the panel follows the mouse. Everything I need to move is chilren of that parent plane. I really don't know how to explain this, after a few secs the plane just "unrenders", and everything along it but that one plane. Sole survivor of a weird code bug.
Here the hole code of the script, maybe it's something from outside the raycast's "if". The important part is just before the last function (infopanelbool)
using UnityEngine;
using System.Collections;
public class Chronos : MonoBehaviour {
public GameObject chronosParent;
public GameObject guiCam;
public GameObject infoPanel;
private MeshRenderer[] infoPanelChildrenMeshes;
public GameObject gameTimer;
public GameObject second3DText;
public GameObject minute3DText;
public GameObject hour3DText;
public GameObject day3DText;
public GameObject month3DText;
public GameObject year3DText;
public GameObject selectorHelper;
public GameObject help3DText;
private int timeSpeed;
public GameObject colliderDrag;
public GameObject colliderInfo;
private Ray _ray;
private RaycastHit _hit;
private bool infoPanelActive;
private float originalZPos;
// Use this for initialization
void Start () {
selectorHelper.transform.localPosition = new Vector3(3.939971F,0.9767007F,1.338649F);
infoPanelActive = true;
infoPanelChildrenMeshes = infoPanel.GetComponentsInChildren<MeshRenderer>();
}
// Update is called once per frame
void Update () {
originalZPos = transform.position.z;
timeSpeed = gameTimer.GetComponent<GameTimer>().timeSpeed;
if( timeSpeed == 1){
selectorHelper.transform.localPosition = new Vector3(3.939971F,0.9767007F,1.338649F);
}
else if( timeSpeed == 2){
selectorHelper.transform.localPosition = new Vector3(2.678372F,0.9767007F,1.338649F);
}
else if( timeSpeed == 3){
selectorHelper.transform.localPosition = new Vector3(1.413278F,0.9767007F,1.338649F);
}
else if( timeSpeed == 4){
selectorHelper.transform.localPosition = new Vector3(0.06286775F,0.9767007F,1.338649F);
}
else if( timeSpeed == 5){
selectorHelper.transform.localPosition = new Vector3(-1.230897F,0.9767007F,1.338649F);
}
second3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().seconds%60;
minute3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().minutes%60;
hour3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().hours%24;
day3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().days%30;
month3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().months%12;
year3DText.GetComponent<TextMesh>().text = "" + (int)gameTimer.GetComponent<GameTimer>().yearsPassed;
_ray = guiCam.camera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(_ray.origin, _ray.direction * 150, out _hit)){
if(Input.GetMouseButtonDown(0)){
if(_hit.collider == colliderInfo.collider){
if(infoPanelActive == false){
infoPanelActive = true;
infoPanelBool();
}
else if(infoPanelActive == true){
infoPanelActive = false;
infoPanelBool();
}
}
}
if(Input.GetMouseButton(0)){
if ( _hit.collider == colliderDrag.collider){
chronosParent.transform.position = _hit.point;
}
} /////UP HERE IS THE IMPORTANT PART
} /////This IF detects the mouse and collider
/////It then tranforms the position of the panel(chronosParent).
}
void infoPanelBool(){
if ( infoPanelActive == true){
infoPanel.renderer.enabled = true;
for(int i=0; i < infoPanelChildrenMeshes.Length; i++){
infoPanelChildrenMeshes[i].renderer.enabled = true;
}
}
else if ( infoPanelActive == false){
infoPanel.renderer.enabled = false;
for(int i=0; i < infoPanelChildrenMeshes.Length; i++){
infoPanelChildrenMeshes[i].renderer.enabled = false;
}
}
}
}
If you got any questions just ask. Any help apreciated, thanks in advance.
Answer by SuIXo3 · Jul 31, 2012 at 09:27 AM
Nevermind, I found the problem. Well I didn't, but I changed the code and now it works.
Can someone close this question?