- Home /
Question by
raisontoast87 · Aug 27, 2016 at 06:50 AM ·
transform.positiononclick
Trigger Transform.Position with Button Click
Hi,
I'm writing a meter that as you click "Swing" (button) it starts an accuracy meter going. This accuracy meter is an sprite that is using Transform.Position and to swing in between to x coordinates, I want the accuracy meter to start OnClick and then further Stop onclick again and return a value of x that I can assign for a miss range to hit a golf ball. Please help!
I don't know much about coding more just learning as I'm building my game
Cheers
using UnityEngine; using System.Collections;
public class AccuracyMeter : MonoBehaviour { private Vector3 startMarker = new Vector3(540,90,0); private Vector3 endMarker = new Vector3(200,90,0); public float speed = 2.5F;
void Start()
{
}
void Update()
{
if (Input.GetButtonDown("Swing"))
{
transform.position = Vector3.Lerp(startMarker, endMarker, (Mathf.Sin(speed * Time.time) + 1.0f) / 2.0f);
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612091635im_/https://answers.unity.com/themes/thub/images/avi.jpg)