Hi, can someone help me with a script. Below is the code that I have for my player. It is a simple drag and shoot script, but I also wanted to make it so that way I can only drag and shoot whenever the player is standing on a pillar. Currently I can drag and shoot him wherever he is. I am pretty new to C# so any help would be wonderful.
public class PlayerMov : MonoBehaviour
{
public float power = 10f;
public Rigidbody2D rb;
public Vector2 minPower;
public Vector2 maxPower;
LineTraj tl;
Camera cam;
Vector2 force;
Vector3 startPoint;
Vector3 endPoint;
private void Start ()
{
cam = Camera.main;
tl = GetComponent<LineTraj>();
}
private void Update()
{
if (Input.GetMouseButtonDown(0))
{
startPoint = cam.ScreenToWorldPoint(Input.mousePosition);
startPoint.z = 15;
}
if (Input.GetMouseButton(0))
{
Vector3 currentPoint = cam.ScreenToWorldPoint(Input.mousePosition);
currentPoint.z = 15;
tl.RenderLine(startPoint, currentPoint);
}
if (Input.GetMouseButtonUp(0))
{
endPoint = cam.ScreenToWorldPoint(Input.mousePosition);
endPoint.z = 15;
force = new Vector2(Mathf.Clamp(startPoint.x - endPoint.x, minPower.x, maxPower.x), Mathf.Clamp(startPoint.y - endPoint.y, minPower.y, maxPower.y));
rb.AddForce(force * power, ForceMode2D.Impulse);
tl.EndLine();
}
}
}
Here is an image of the scene:
Thanks