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
0
Question by Razputin · Feb 20, 2014 at 05:34 PM · guitriggerrandom

How to get random GUI to appear, on entering a trigger. (PIC INCLUDED)

So i'm trying to make random gui's appear when the player enters a trigger. I'm not sure if random gui's are the right things to use for this. If anyones played Mount and Blade i'm trying to make it like that were theres a description of some stuff thats happening overlayed on a picture, and then several options that you can choose from to respond to what is happening.

I know this script doesn't work I just made it to be a rough idea of what i'm trying to do.

using UnityEngine; using System.Collections; public class DetectGridGrassland : MonoBehaviour { void OnTriggerEnter(Collider other) { Debug.Log("Player entered the Grass Land"); float rnd = Random.value; if ( rnd < 0.05 ) { GUI.Box (Rect (10,10,100,90), "Attacked by bandits"); } else if ( rnd < 0.15 ) { GUI.Box (Rect (10,10,100,90), "Attacked by wolves"); } else { GUI.Box (Rect (10,10,100,90), "Nothing happens"); } } } }

Here is what i'm trying to achieve. alt text

mountnbladeconvo.jpg (39.2 kB)
Comment
Add comment · Show 1
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 Razputin · Feb 20, 2014 at 07:43 PM 0
Share

I could also maybe instantiate the picture in front of the camera and then overlay the buttons over the choices or something maybe?

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Stormizin · Feb 20, 2014 at 08:03 PM

Try something like that actually in C#:

 public int randNum = 0;
 
 void Start(){
 randNum = Random.Range(0,5);
 }
 
 void OnGUI(){
 if (randNum <= 3){
 GUI.Button(new Rect(10, 10, 125, 25), "Attacked by bandits");
 }
 else if(randNum == 3){
 GUI.Button(new Rect(10, 10+20, 125, 25), "Attacked by wolves");
 }
 else{
 GUI.Button(new Rect(10, 10+30, 125, 25), "Nothing to do!");
 }
 }

You can also do it with an array, it's a cleaner code and better to control.

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

19 People are following this question.

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

Related Questions

triggering random animations with gui 1 Answer

Why can't void be used in this context? 2 Answers

Can I set a specific Pointer for the EventTrigger on Buttons for example? 0 Answers

How do I use a trigger to change the GUIText 2 Answers

Clicking an Object on IPAD when within a Certain Distance 0 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