Hello everyone. I am doing a rts-like demo just to learn more about Unity. What i am trying to do is getting a region between two vectors
So when i click once. I will get the start position on the map. and when i release the mouse, i want the end position and the start position to have a region between each other
What i have so far!
using UnityEngine;
using System.Collections;
public class TargetRegion : MonoBehaviour
{
Vector3 _startposition;
Vector3 _endposition;
[SerializeField]
GameObject _region; // Is a rectangle trigger
bool rightclick;
void Start ()
{
rightclick = false;
}
void Update ()
{
if(Input.GetButtonDown("Fire1"))
{
RaycastHit hitinfo;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitinfo))
{
_startposition = hitinfo.point;
}
rightclick = true;
Instantiate(_region);
_region.transform.position = _startposistion;
}
if(rightclick == true)
{
RaycastHit hitinfo;
if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hitinfo))
{
_endposition = hitinfo.point;
}
}
if(Input.GetButtonUp("Fire1"))
{
rightclick = false;
}
}
}
I am raycasting the first and the last posistion. But what i need help with is making the region between the two. So any tips would be helpful.