- Home /
Dragging out objects with touch on Android
hey everyone. I already have a script which allows me to touch to spawn an arrow that faces a ball (which is also in the scene) What im after however is when touched the arrow tip will be near enough attached to the ball, allowing the player to drag his/her finger away from the ball making the arrow larger.
My question is how can i create a second point of the arrow which the current finger position is attached to. im guessing the arrow spawn point would be to an empty in the ball, but how would i make the back of the arrow follow the position of the touch?
the script i have so far is this (this only works in orphographic camera, couldnt make it function for perspective)>
// using UnityEngine; using System.Collections;
public class TouchDragControls : MonoBehaviour {
public GameObject arrowPrefab;
public Transform Ball;
GameObject Arrow;
Vector3 StartPos;
Vector3 CurrentPos;
Vector3 CreatePos;
// Update is called once per frame void Update () {
// If screen is touched and arrow doesnt exist if(Input.touchCount > 0 && !Arrow) { // Make start position
StartPos = Input.GetTouch(0).position;
CreatePos = Camera.main.ScreenToWorldPoint (StartPos);
CreatePos += Camera.main.transform.forward * 10;
Debug.Log (StartPos);
Debug.LogWarning (CreatePos);
Arrow = Instantiate(arrowPrefab, CreatePos, Quaternion.identity) as GameObject;
Arrow.transform.LookAt(Ball);
}
}
}