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;
}
}
}
}
Exactly. And that's the problem. There should be an in-built solution to prevent these things, but I don't think there is. Haven't found it atleast.
– TruffelsAndOranges