- Home /
How do shoot a bullet when the right button is clicked?
This script is similar to Starcraft's Marauder. This enables the object it's attached to move to the place where the pointer is located when the left mouse button is clicked.
How do you make it shoot a bullet when the right button is clicked? I don't need the whole code, I just need a pseudo-code.
Example: http://www.youtube.com/watch?v=LHYS76d7aEU
using UnityEngine; using System.Collections;
public class Marauder : MonoBehaviour {
// Use this for initialization void Start () {
}
public float Speed = 0.1f; private Vector3 location; private bool InTransit;
// Update is called once per frame void Update () { //=================================== if (Input.GetMouseButtonUp(0)) { Vector3 mousePos = Input.mousePosition; Ray ray = Camera.main.ScreenPointToRay(mousePos);
RaycastHit hitInfo;
if (Physics.Raycast(
ray, out hitInfo, Mathf.Infinity))
{
location = hitInfo.point;
InTransit = true;
}
}
//===================================
if (InTransit == true)
{
Vector3 Direction = location -
this.transform.position;
if (Direction.magnitude > Speed)
{
this.transform.position +=
Direction.normalized * Speed;
}
else
{
InTransit = false;
}
}
}
}
Answer by Justin Warner · Apr 12, 2011 at 02:22 AM
http://unity3d.com/support/documentation/ScriptReference/Object.Instantiate.html
That to actually make the bullet...
Um... and looks like you already have the Input, so just put that in the if statement, and you'd be good I'd expect.
Your answer
Follow this Question
Related Questions
I have a problem with fire and reload in my GUN SCRIPT 1 Answer
Best way to make a gun? 1 Answer
Control amount of bullets 2 Answers
Gun Script 1 Answer