Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 forrest117 · May 31, 2011 at 01:00 AM · javascriptrandomweaponmario kart

Mario Kart Style random weapon

I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help

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
2

Answer by Flafla2 · May 31, 2011 at 01:12 AM

This is a situation where if you actually knew Unityscript you would know what the solution is... Let's go through your question by looking at Key words: I want to make a mario style game and i want to make it so that a game object will give me a random weapon when i drive over it and also the object would have to respawn after a few seconds. Please help

Alright, the first keyword is game object. So you need to have a gameobject in your scene, and call it a certian name.

Random:Duh... Random.Range

Drive Over It: Colliders. Rigidbodies. Yay.

Respawn: Instantiate the "Item box" gameobject.

A few Seconds: Time, *Time*, ***Time!***

I hope this answers your question.

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
0

Answer by save · May 31, 2011 at 01:05 AM

You could do this on OnTriggerEnter(), select a random object with Random.Range(minval, maxval) and make use of yields to wait for the respawn (could be the objects renderer switch on/off).

Comment
Add comment · Show 2 · 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 forrest117 · May 31, 2011 at 01:13 AM 0
Share

But could i use Arrays with it? and how would i go about that exactaly in script? sorry im a noob

avatar image save · May 31, 2011 at 02:04 AM 0
Share

Yeah you definitely could apply an array to it, just use var weaponOfRandomChoice : GameObject = weapons[Random.Range(0, weapons.length)]. The array itself could store the actual GameObjects or otherwise integers, it all depends on how you want to wrap things up to finally give the randomized weapon to the player.

avatar image
0

Answer by eeveelution8 · May 10, 2014 at 07:10 PM

I don't know how to do it either, but here's a good starting script to go with.

 var items : GameObject [];
  
 function OnTriggerEnter()
 {
     collider.enabled = false;
  
     var index : int = Random.Range(1,items.length);
     var thePrefab : GameObject = items[index];
  
     var instance : GameObject = Instantiate(thePrefab, transform.position, transform.rotation);
  
 }
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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Random.Range statement question 1 Answer

Sound playing at random. (JS) 2 Answers

Having random operators in an equation? 1 Answer

Adding GUI to this 1 Answer

Spawn random amount of gameobjects 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