Apologies for the poorly described title. My brain is fried. The problem below in the picture… I want to move that capsule in any direction via a mouse click but not outside the circle. The circle is a texture on a plane attached to the capsule object. So I did this bit of code:
using UnityEngine;
using System.Collections;
public class UnitMove : MonoBehaviour {
public Transform moveTo;
public int moveSpeed;
public int rotationSpeed;
void Start () {
}
void Update () {
if (Input.GetMouseButtonDown(1)) {
GameObject[] sl;
sl = GameObject.FindGameObjectsWithTag("White");
foreach(GameObject slt in sl) {
UnitStats us = (UnitStats)slt.GetComponent("UnitStats");
if (us.selected == true && us.movementphase == 0) {
RaycastHit hit;
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(ray, out hit) && hit.transform.tag == "selectedmovecircle"){
moveTo = hit.transform;
Debug.Log (moveTo);
moveUnit();
}
}
}
}
}
void moveUnit() {
}
}
Which I was very proud of. In moveUnit() I’ll move the unit to moveTo. Now obviously I didn’t think ahead and realise that Unity won’t see that circle as a circle! It just sees the square-shaped plane. So my little capsule can move outside the circle to the corner edges of the plane.
Any ideas on the best way to get around this? Or am I going to have to get into some trigonometry (gulp)? Is another way better anyway?
Thanks.
Bonus Secondary Question! Can anyone give me a pointer which commands I should be looking at to not render the part of that circle texture that is hanging over the side of the grass?