Logo my studio is game, portfólio is developer game

Randon.Range - Random numbers in Unity 

To have random numbers in games built in Unity, the game programmer has at his disposal the Randon. Range. 

In this post I will make an example of percentage chances of something happening, in my case of life or death. 

using UnityEngine;
using System.Collections;

public class RandonRange : MonoBehaviour
{
    #region Variables basics
    [SerializeField][Range(0,100)] private float percent;
    #endregion

    #region Methds in Unity
    private void Update()
    {
        if (Input.GetButtonDown("Jump"))
        {
            RandomPercent();
        }
    }
    #endregion

    #region Methds custon
    private void RandomPercent()
    {
        int value;
        value = Random.Range(0, 100);

        if (value <= percent)
        {
            Debug.Log("Life... =] "+value);
        }
        else
        {
            Debug.Log("Death... =/ "+value);
        }
    }
    #endregion

}

 

Make contact!

Did you like this content? Let's talk...

I'm a game developer, I use unity. If you want to develop something, tell me!