I am making a first person game with melee weapons.
I want to make a script that plays a random attack animation when I press the left mouse button. I have tried to make a script, however it’s not working. when I press the mouse button, it gives me this error: “NullReferenceException: Object reference not set to an instance of an object”
here is the script:
var allmotions : AnimationClip[];
var textFieldString = "text field";
function Start () {
for (var i = 0; i < allmotions.Length; i++)
animation.AddClip(allmotions*, "random"+i);*
}
function Update()
{
var randomAnim = allmotions[Random.Range (0, 0)];
-
if(Input.GetButtonDown(“Fire1”))*
-
{*
transform.identity.animation.Play (“” + randomAnim);
- }*
}
Your help would be much appreciated.