Hello ,
Here i want to fire continuously when user hold button…
For that i have created Plane game object with button texture… And Set collider on that plane game object…
When user hold that button i want to fire continuously … For that i have tried code which is below :
if(Input.GetMouseButton(0))
{
var hit : RaycastHit;
var ray : Ray = Camera.mainCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray,hit))
{
if(hit.collider.gameObject.GetComponent("ButtonId"))
{
buttonPressed = hit.collider.gameObject.GetComponent("ButtonId");
if(buttonPressed.id == "Fire")
{
HandleBullet();
}
}
}
}
function HandleBullet()
{
spawnPoint = GameObject.Find("Bullet");
if(spawnPoint != null)
{
if(playerScript.State != state.Explosion)
{
bulletObject = Instantiate(projectilePrefab, spawnPoint.transform.position,spawnPoint.transform.rotation);
}
}
}
I have written this script… but its not working for rapid fire…
Anyone is having idea then please suggest me…
Thanx for ur support and help in advance…
what are the problems you are facing and what type of game is this so that i can help you with the fire code script
– deltamishkind of space shooter 2d game.. ship moves right and left and shoot bullet..
– Ekta-Mehta-Dyou can make the GetMouseButtonDown(0) switch a boolean to true, which makes the gun fire continuosly and then you check GetMouseButtonUp(0) you witch it to false again.
– ragnaros100Please tell me the mouse input is inside a function. Try Debugging at line 10 before the if : Debug.Log( "buttonPressed.id = " + buttonPressed.id );
– AlucardJayfire works for single click.. if i want to fire again,then i need to click
– Ekta-Mehta-D