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 CyrusGordonW · Aug 08, 2012 at 01:13 PM · randomgunrpgstats

How would I go about making randomised guns, borderlands-style?

I'm making an RPG/FPS and I want guns to have random attachment(s) and I want their stats to vary within a certain boundary for each weapon type. The gun would consist of a base and a mixture one or more of the following: a site/scope attachment, a torch or laser attachment, a silencer attachment or some other muzzle peripheral which adds elemental damage and an attribute which boosts the character's attack, defense, reload xp ect.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by aldonaletto · Aug 08, 2012 at 01:51 PM

I would create the weapon with all the optional items childed to it, and randomly activate/deactivate each item at Start - like this:

// drag the extras items to the appropriate fields: var scope: GameObject; var laser: GameObject; var silencer: GameObject;

private var hasScope: boolean; private var hasLaser: boolean; private var hasSilencer: boolean;

function Start(){ hasScope = Random.value < 0.20; // scope chance: 20% hasLaser = Random.value < 0.35; // laser chance: 35% hasSilencer = Random.value < 0.25; // silencer chance: 25% scope.SetActiveRecursively(hasScope); laser.SetActiveRecursively(hasScope); silencer.SetActiveRecursively(hasScope); } The hierarchy for such weapon should be something like this:

  Weapon // "naked" weapon (without any extras)
    Scope // scope model
    Laser // laser model
    Silencer // silencer model
You can use the variables hasScope, hasLaser etc. to enable the corresponding features in your script.
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 IndieScapeGames · Aug 08, 2012 at 02:53 PM 0
Share

Nicely done, I started with just a small example, but you definitely took it up a notch. +1

avatar image
0

Answer by IndieScapeGames · Aug 08, 2012 at 02:52 PM

Well you'll need a ton of media, which is models, textures, animations, and other resources for visuals.

Coding, which this portion of the Unity site is about, would be a bit more difficult but let's look at just one random value: size of clip.

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {
     public int numberOfRounds;
     void Start() {
         numberOfRounds = Random.Range(1, 32);
     }
 }

This particular instance assigns a random number, from 1 to 32, to the number of rounds. Using your logic for reloading and firing, you would refer to this number of ammunition and subtract from it as you fired.

Something hints that this may be your first game. If so, start smaller, don't try to create Borderlands or the next World of Warcraft.

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

9 People are following this question.

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

Related Questions

Gaussian Distribution in circle on x and y axis 1 Answer

temporarily change variable(buff system) 1 Answer

Getting XP when dies Help 1 Answer

C# Random Stats Distribuition 3 Answers

More elegant way to constantly update player health algorithms. 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