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 ryuuri · Dec 25, 2011 at 10:13 PM · randompicturedice

Random picture picker

I'm new to Unity and what i'm trying to do is have a button which will keep going through several pictures then pick one like a slot machine. Depending on what picture you get the game will let you do something different. For example if you get a movement picture lets you move, if you get a attacking picture you can attack. Not too sure where to start with this.

Comment
Add comment · Show 3
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 ryuuri · Dec 26, 2011 at 08:37 PM 0
Share

Something along these lines

static var RandomNum: int; var DiceSound : AudioClip;

function Update(){ if(Input.Get$$anonymous$$eyUp("r")){ RandomNum = Random.Range(1,6); } if(RandomNum == 1){ audio.clip = DiceSound; audio.PlayOneShot(DiceSound); } }

Then do something else if its another number.

avatar image Chris 26 · Dec 26, 2011 at 08:54 PM 0
Share

What is it exactly you aren't sure about?

Besides, whouldn't it be better to play the sounds inside the >>if(Input.Get$$anonymous$$eyUp("r")<

avatar image ryuuri · Dec 26, 2011 at 09:06 PM 0
Share

Ah sorry it all got squashed together. The audio was put into that bit to see whether it was working. I'm getting a error when I press R. "$$anonymous$$issing$$anonymous$$ethodException: $$anonymous$$ethod not found: 'Random.Range'. How would I make it display the associated picture with the number it generates?

1 Reply

· Add your reply
  • Sort: 
avatar image
4

Answer by Rod-Green · Dec 26, 2011 at 09:38 PM

Firstly you might need to think of more like random 'card' picker rather than just a picture or texture. Semantics I know but it's good to think about it as game concept rather than a literal asset concept.

So with that said how about creating this:

 using System.Collections.Generic;
 using UnityEngine;
 
 
 public enum GameCardType
 {
     MOVEMENT,
     OTHER_TYPES_HERE,
     ENUM_COUNT
 }
 
 
 
 public class GameCardGame : MonoBehaviour
 {
     public bool m_playGame;
     public Texture2D[] m_cardTextures; // assign matching textures to this property
     public GUITexture m_cardGUITexture;
     
     //Assigned random card
     private GameCardType m_curType;
     
     //Picks a random card type
     static GameCardType GetRandom()
     {
         return (GameCardType)Random.Range(0, (int)GameCardType.ENUM_COUNT);
     }
     
     //Movement code
     void DoMovementType()
     {
         Debug.Log("Movement code!");
     }
     
     void DoOtherType()
     {
         Debug.Log("Other type code!");
         
     }
     
     //Plays the game
     void PlayGame()    
     {
         // Get a random card
         m_curType = GetRandom();
         
         //if not null and texture exists - assign the selected type to GUITexture
         if(m_cardTextures != null && (int)m_curType < m_cardTextures.Length
            && m_cardGUITexture != null)
             m_cardGUITexture.texture = m_cardTextures[(int)m_curType];
         
         
         // Do random card logic
         switch (m_curType)
         {
             case(GameCardType.MOVEMENT):
                 DoMovementType();
                 break;
             case(GameCardType.OTHER_TYPES_HERE):
                 DoOtherType();
                 break;
             default:
                 Debug.LogWarning("No method specified for card type!");
                 break;
         }
         
     }
     
     
     //Update loop to catch the m_playGame bool trigger
     void Update()
     {
         if(m_playGame)
             PlayGame();
         m_playGame = false;
     }
 
 }
Comment
Add comment · Show 1 · 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 ryuuri · Dec 27, 2011 at 12:06 AM 0
Share

Woah thanks for all that i'll try getting it working, gotta work my head around it first :)

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

java scrip, dice throw at a random rotation and force? 1 Answer

Randome Number for Dice 2 Answers

How do you script to show random image for seconds? 2 Answers

Dice Animation and Face Determination 7 Answers

Creating a light in game C# 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