Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by Alanimator · Jan 01, 2012 at 09:00 PM · none

Character Contolller Hit

I am trying my best to have my object which this code has been attached to react with a simple plane which has been tagged with the name "pann" , when my object touches pann it should respawn and generate a GUI window saying "you died"

Here is my code

var speed =4.0; var rotateSpeed =4.0; var dicePrefab : Transform ; // TRANSFORM private var panel = false; function OnControllerColliderHit (hit: ControllerColliderHit) {

if(hit.gameObject.tag == "pann") { panel= true; }

}

function Update () { var controller : CharacterController = GetComponent (CharacterController); transform.Rotate (0, Input.GetAxis ("Horizontal") rotateSpeed , 0); var forward =transform. TransformDirection (Vector3 .forward); var curSpeed =speed Input.GetAxis ("Vertical"); controller.SimpleMove (forward * curSpeed);

}

function LateUpdate ()

  if (panel)
  {
      transform.position = Vector3 (80,50,0);
     // gameObject.Find()
     // I  tried putting a gui box here  / OnGUI doesnt seem to work anywhere in this code.
     
     panel = false ;
  }

}

Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by kievar1983 · Jan 01, 2012 at 10:00 PM

to generate a gui window you actually need to call it through

void OnGUI ()

your best bet is most likely to store some boolean value and set it when the collision is true then do an if statement for the onGUI.

Comment
Add comment · 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
avatar image
1

Answer by nastasache · Jan 01, 2012 at 10:27 PM

It's apparently not working with your onGUI() function just because the box with text "you died" immediately disappearing.

Try:

 function OnGUI ()
 
      if (panel)
      {
          transform.position = Vector3 (80,50,0);
         // gameObject.Find()
         // I  tried putting a gui box here  / OnGUI doesnt seem to work anywhere in this code.
         
         ///panel = false ; /// Here's the point; make it false in other way/place
      }
 
 }
Comment
Add comment · 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
avatar image
1

Answer by aldonaletto · Jan 01, 2012 at 11:49 PM

You should use a float timer variable instead of the boolean panel, because the box must stay in screen during some time, then disappear and move the character to the respawn position. Change your code to this:

var speed =4.0; var rotateSpeed =4.0; var dicePrefab : Transform ; // TRANSFORM

function Update () { var controller : CharacterController = GetComponent (CharacterController); transform.Rotate (0, Input.GetAxis ("Horizontal") rotateSpeed , 0); var forward = transform.TransformDirection (Vector3.forward); var curSpeed = speed Input.GetAxis("Vertical"); controller.SimpleMove (forward * curSpeed); }

private var timer: float = 0;

function OnControllerColliderHit (hit: ControllerColliderHit){ if(hit.gameObject.tag == "pann"){ timer = 3; // load the timer with 3 seconds } }

function OnGUI(){ if (timer > 0){ // if timer not zeroed, display the box var r = Rect((Screen.width-210)/2, (Screen.height-80)/2, 210, 80); GUI.Box(r, "You're dead!"); } }

function LateUpdate(){ if (timer > 0){ // if timer not zeroed yet... timer -= Time.deltaTime; // decrement timer... if (timer

Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

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

Related Questions

Object refernce not set to an instance of an object .... 1 Answer

None (Physics Material) Properties 1 Answer

How to set physics material to "none" via script? 2 Answers

Objects dissapearing when i press play (unity 5) 0 Answers

Event.current.keyCode doesnt return shift 2 Answers


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