• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by SuIXo3 · Jul 30, 2012 at 08:03 PM · raycastcolliderdragrayhit

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.

Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

  • Sort: 
avatar image
Best Answer

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?

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Unity Answers is in Read-Only mode

Unity Answers content will be migrated to a new Community platform and we are aiming to launch a public beta by June 9. Please note, Unity Answers is now in read-only so we can prepare for the final data migration.

For more information and updates, please read our full announcement thread in the Unity Forum.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I don't know why i can't detect by ray sth. tagged, 1 Answer

how to get info on what raycast hitted 1 Answer

Need Help with RayCast. No Vector? 1 Answer

why are child colliders sometimes ignored? 2 Answers

Someone can help with Ray/Collide? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges