- Home /
ArgumentNullException: Argument cannot be null
I keep getting the error ArgumentNullException: Argument cannot be null. of my script. Its basically teling a gameObject (I named "Enemy") with a CharacterController to play sound whenever it moves horizontally and/or vertically.
var footsteps : AudioClip;
var CharacterController;
function Start()
{
audio.clip = footsteps;
audio.loop = true;
}
function Update()
{
if (CharacterController("Horizontal") != 0 || CharacterController("Vertical") != 0)
{
if(!audio.isPlaying)
audio.Play();
}
else if(CharacterController("Horizontal") == 0 && CharacterController("Vertical") == 0)
audio.Stop();
}
What's more wierd is despite of the error I could still play the game just fine but it is annoying that whenever I look at my console box for debugging this same error display every frame.
EDIT: For more detail: I am trying to play a footstep audio clip whenever the gameObject (the Enemy) moves. It works but this error always show up in my console box.
You have a variable named CharacterController which is also a type, and is probably not a good idea.
What line is giving the error? Do you have an audiosource attached to your gameObject? Is this going to be the only audio that is played by this gameobject?
It is line 24 I believe. I only have one audio clip at the moment. it is just a few seconds of footstep sounds looped.
This works with my Player, so when I move horizontally or vertically it plays the adui, but not with the Enemy AI.
It is line 24 I believe. I only have one audio clip at the moment. it is just a few seconds of footstep sounds looped.
This works with my Player, so when I move horizontally or vertically it plays the audio, but not with the Enemy AI.
I'm basically trying to tell the object that whenever it moves horizontally or vertically, play the audio.
Your problems:
Your variable
CharacterController
has notype
and is therefore oftype
:Object
by default.There is a name conflict between your variable
CharacterController
and the UnityEnginetype
:CharacterController
You are calling your variable. Unless your variable is a (non-behaviour)
type
or a function you should (and cannot) call it.How to fix it:
Add #pragma strict
to the top of your file and fix the compiler errors (`strict` gives very good recommendations for error fixing)
Also
Please don't leave so much white-space in your question, it's really annoying to read.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Move Object Smoothly 1 Answer