- Home /
Problem'' not compatible with the argument list '(String)'.''
this is the scipt: how to fix ?
function Update() {
var aniPlay = GetComponent ( "aniSprite" ); //aniPlay.aniSprite (16, 16, 0, 0, 16, 12 ); var controller : CharacterController = GetComponent(CharacterController);
if (controller.isGrounded)
{
jumpEnable = false;
runJumpEnable = false;
crouchJumpEnable = false;
velocity= Vector3(Input.GetAxis("Horizontal"), 0,0 );
if ( velocity.x == 0 && moveDirection == 1 )
{
aniPlay.aniSprite (16, 16, 0, 0, 16, 12 );
}
if ( velocity.x == 0 && moveDirection == 0)
{
aniPlay.aniSprite (16, 16, 0, 1, 16, 12 );
}
if ( velocity.x < 0 )
{
velocity *= walkSpeed;
aniPlay.aniSprite ( 16, 16, 0, 3, 10, 15 );
}
if ( velocity.x > 0 )
{
velocity *= walkSpeed;
aniPlay.aniSprite ( 16, 16, 0, 2, 10, 15 );
}
if (velocity.x < 0 && Input.GetButton ( "Fire1" ) )
{
velocity *= runSpeed;
aniPlay.aniSprite ( 16, 16, 0, 5, 16, 24 );
}
if (velocity.x > 0 && Input.GetButton ( "Fire1" ) )
{
velocity *= runSpeed;
aniPlay.aniSprite ( 16, 16, 0, 4, 16, 24 );
}
if ( velocity.x == 0 && Input.GetAxis ( "Vertical" ) < 0)
{
if ( moveDirection == 0 )
{
velocity.x = 0;
aniPlay.aniSprite ( 16, 16, 0, 9, 16, 24 );
}
if ( moveDirection == 1 )
{
velocity.x = 0;
aniPlay.aniSprite ( 16, 16, 0, 8, 16, 24 );
}
}
if ( Input.GetButtonDown ( "Jump" ) && ( !Input.GetButton ( "Fire1" ) ||Input.GetButton ( "Fire1") && velocity.x == 0 ) && Input.GetAxis ( "Vertical" ) >= 0 )
{
velocity.y = walkJump;
jumpEnable = true;
}
if ( Input.GetButtonDown ( "Jump" ) && Input.GetButton ( "Fire1" ) && velocity.x !=0 )
{
velocity.y = runJump;
runJumpEnable = true;
}
if ( Input.GetButtonDown ( "Jump" ) && velocity.x == 0 && Input.GetAxis ( "Vertical" ) < 0 )
{
velocity.y = crouchJump;
crouchJumpEnable = true;
}
}
if ( !controller.isGrounded )
{
if ( Input.GetMouseButtonUp ( "Jump" ) ) // #ERROR
{
velocity.y = velocity.y - fallSpeed;
}
velocity.x = Input.GetAxis ( "Horizontal" );
velocity.x *= walkSpeed;
}
if ( velocity.x < 0 )
{
moveDirection = 0;
}
if ( velocity.x > 0 )
{
moveDirection = 1;
}
velocity.y -= gravity * Time.deltaTime;
controller.Move ( velocity* Time.deltaTime );
}
You should actually post the complete exception/error, you could post the relevant script/code that include the lines it is referencing.
You post it here. Don't say "there is an error", say which line specifically has the error, ins$$anonymous$$d of expecting people to hunt it down.
In all fairness, he did mark the error line with a comment. But, it was hard to spot and definitely not the most helpful way of communicating the problem.
Ah, so he did. I scanned the code looking for a comment originally, but didn't see it.
Answer by Dave-Carlile · Dec 19, 2012 at 04:56 PM
If you look at the documentation for Input.GetMouseButtonUp, it doesn't take a string as a parameter, but a button index.
This is correct.
@Jaspb97 Input.Get$$anonymous$$ouseButtonUp(0) will return true the same frame the left mouse button was let up.
Input.Get$$anonymous$$ouseButton(0) will return true EVERY frame the left mouse button is DOWN and false EVERY frame the left mouse button is up.
Alternatively you could use Input.GetAxis("Fire1") as the second method (returns true every frame the left mouse button is down, and false while up).
thnx sooooooooo and soooo and ssooooo muchhhhh!!!!!!!!!!! ;)
Answer by Next Beat Games · Dec 19, 2012 at 07:02 PM
a couple ways to improve your methodology: make aniPlay & controller public and attach the objects in the inspector at design time instead of getting the component during runtime. This works only when you know when the assignment wont be dynamically chosen at run time.
also, whenever you are using the equality operator (the ==), place the constant to the left of the operator instead of on the right. that way, if you accidentally use assignment operator (=) instead of equality operator(==) you will get a compiler error instead of a logical error. eliminates bug tracking.
Eg. instead of if (velocity.x == 0), use if (0 == velocity.x)
Actually you get an error if you try to use = ins$$anonymous$$d of == anyway, so the order isn't relevant.
Your answer
Follow this Question
Related Questions
JavaScript Grid Array Size 0 Answers
UI Masking a GameObject 2 Answers
Null Reference Exception upon entering vehicle 1 Answer
Disable item after 10 shots. 2 Answers
Select and deselect in Editor via C# 1 Answer