I want to create an AirStrike ability for a RTS game. Before the planes launch, I want to set the position and rotation of the “Strike Zone”. I have this code, where I can rotate the object, but not on the mouse position.
Here is the code:
public class AirStrikeAbility : MonoBehaviour
{
public float rotSpeed = 20;
public GameObject camera;
public bool mousePressed = false;
// Update is called once per frame
void Update()
{
if (mousePressed == true)
{
camera.GetComponent<RTSCameraController>().enabled = false;
}
}
private void OnMouseDown()
{
mousePressed = true;
}
private void OnMouseDrag()
{
float rotX = Input.GetAxis("Mouse Y") * rotSpeed * Mathf.Deg2Rad;
transform.RotateAround(Vector3.up, -rotX);
}
private void OnMouseUp()
{
mousePressed = false;
camera.GetComponent<RTSCameraController>().enabled = true;
}
}