unity divider in variable code example
Example 1: unity separator in inspector
using UnityEngine;
public class Example : MonoBehaviour
{
//Use this PropertyAttribute to add a header above some fields in the Inspector.
[Header("Hi there!")]
//Space between variables
[Space(10)]
//Attribute used to make a float or int variable in a script be restricted to a specific range.
//public RangeAttribute(float min, float max);
[Range(5,9)]
public string playerName = "Unnamed";
}
Example 2: how to make a variable unchangeable in java
class scratch{
public static void main(String[] args){
final pi = 3.14;
}
}
Example 3: how to make % posibility to spawn an object C# in unity
public class RandomTimeSpawner : MonoBehaviour { //Spawn this object public GameObject spawnObject; public float maxTime = 5; public float minTime = 2; //current time private float time; //The time to spawn the object private float spawnTime; void Start(){ SetRandomTime(); time = minTime; } void FixedUpdate(){ //Counts up time += Time.deltaTime; //Check if its the right time to spawn the object if(time >= spawnTime){ SpawnObject(); SetRandomTime(); } } //Spawns the object and resets the time void SpawnObject(){ time = minTime; Instantiate (spawnObject, transform.position, spawnObject.transform.rotation); } //Sets the random time between minTime and maxTime void SetRandomTime(){ spawnTime = Random.Range(minTime, maxTime); } }