So for testing purposes, I’m trying to get my player to move forward a set distance with a click of a menu button but it will switch for it to be either keyboard or mouse. Problem is since I’m not using the Update(), it only moves the player one frame at a time so you have to click the button until it’s finished.
When I tried to use a while or a do-while loop it froze up Unity so I doubt that I can use them but if you can figure out something then I super applaud you!
using UnityEngine;
using System.Collections;
public class BattleMovement : MonoBehaviour {
public GameObject player;
public GameObject obj;
public RaycastHit hit;
private Vector3 velocity = Vector3.zero;
public void MoveSquare() {
player = GameObject.Find ("GameObject");
obj = GameObject.Find ("space");
Vector3 fwd = player.transform.TransformDirection (Vector3.forward);
Vector3 tileJump = player.transform.position + new Vector3 (100, 0, 0);
if (Physics.Raycast (player.transform.position, fwd, 100.0f)) {
print ("There is something in front of the object!");
player.transform.position = Vector3.SmoothDamp (player.transform.position, tileJump, ref velocity, 0.3f);
}
}
}