- Home /
What is wrong with this shooting script?
I am creating a script that'll make my gun shoot ready made bullets. I have an invisible spawnpoint infront of the gun. (FPS)
Here's the script:
var BulletPrefab:Transform;
var force : float = 2000;
function Update ()
{if(Input.GetMouseButtonDown("Fire1"))
{var bullet = Instantiate(BulletPrefab,
GameObject.Find("spawnPoint").transform.position,
GameObject.Find("AK-47M").transform.rotation);
bullet.rigidbody.AddForce(bullet.transform.forward * force);
}
}
But I get the error message: Assets/FPSScripts/shoot.js(5,25): BCE0017: The best overload for the method 'UnityEngine.Input.GetMouseButton(int)' is not compatible with the argument list '(String)'.
And i don't get how i should make it shoot when i press leftclick in my mouse. anyone willing to help?
Answer by poncho · Feb 11, 2013 at 05:17 PM
The best overload for the method 'UnityEngine.Input.GetMouseButton(int)' is not compatible with the argument list '(String)'. means it needs an int value as a parameter like 0,1,2
Input.GetMouseButton(0) --> leftClick
Input.GetMouseButton(1) --> RightClick
Input.GetMouseButton(2) --> MiddleClick
http://docs.unity3d.com/Documentation/ScriptReference/Input.GetMouseButton.html
cheers
Now it stands: Assets/FPSSCRIPTS 1/Shootingscript.js(5,29): BCE0077: It is not possible to invoke an expression of type 'boolean'.
why so many errors? :(
Answer by GothicsoulSeiji · Feb 11, 2013 at 06:03 PM
Now it stands: Assets/FPSSCRIPTS 1/Shootingscript.js(5,29): BCE0077: It is not possible to invoke an expression of type 'boolean'.
why so many errors? :(
by that code i meant
if(Input.Get$$anonymous$$ouseButton(0))
ins$$anonymous$$d of
if(Input.Get$$anonymous$$ouseButtonDown("Fire1"))
when something returns a boolean it means the method gives you a true or false, i would recommend a basic program$$anonymous$$g read