hey all,
Im trying to have an effect where the player will click on the screen, and while holding the mouse down, they are able to drag out an arrow shape which points at the position where the mouse click was 1st made.
i know id need the positions of the mouse click and the currrent position, but im not sure how to instantiate a plane which pointed towards the startPOS while the rear end is linked to currentPOS, thats if its even possible?
The Vectrosity package in the Asset store makes drawing lines and arrows easy. Depending on what you are doing, it may be a good solution.
Here is another solution. To test it:
- Get the CreatePlane script from the Wiki.
- Create a 1 unit Vertical plane
- Put whatever material you want on the plane. Note the point of the arrow should be up. You will have to do the arrowhead as a separate object if you don’t want it stretched.
- Attach this script
- Set the x in the scale to .001.
Hit play and click and drag.
#pragma strict
private var pos1 : Vector3;
private var pos2 : Vector3;
var objectHeight = 1.0;
function Update () {
if (Input.GetMouseButtonDown(0)) {
pos1 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos1 = Camera.main.ScreenToWorldPoint(pos1);
pos2 = pos1;
}
if (Input.GetMouseButton(0)) {
pos2 = Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane + 0.5);
pos2 = Camera.main.ScreenToWorldPoint(pos2);
}
if (pos2 != pos1) {
var v3 = pos2 - pos1;
transform.position = pos1 + (v3) / 2.0;
transform.localScale.y = v3.magnitude;
transform.rotation = Quaternion.FromToRotation(Vector3.up, v3);
}
}