Associate an Alias to Resolve Conflicts
suggest changeIf you are using multiple namespaces that contain classes with the same name (such as System.Random and UnityEngine.Random), you can use an alias so that Random refers to one of them without writing the full namespace at each use.
For instance:
using UnityEngine;
using System;
Random rnd = new Random();
This will cause the compiler to be unsure which Random to evaluate the new variable as. Instead, you can do:
using UnityEngine;
using System;
using Random = System.Random;
Random rnd = new Random();
This doesn’t preclude you from calling the other type by its fully qualified name:
using UnityEngine;
using System;
using Random = System.Random;
Random rnd = new Random();
int unityRandom = UnityEngine.Random.Range(0,100);
rnd is a System.Random. unityRandom is the int returned by UnityEngine.Random.Range, not a UnityEngine.Random instance.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents