using System.Collections; using System.Collections.Generic; using UnityEngine; public class newmove : MonoBehaviour { private Rigidbody rb; Vector3 pos; private Vector3 distance; public float speed = 6f; Vector3 tempP; public float maxY; public float minY; public float maxX; public float minX; void Start() { rb = GetComponent<Rigidbody>(); tempP = transform.position; } // Update is called once per frame void FixedUpdate() { // If the game is paused, don't do anything if (PauseScreenBehaviour.paused) return; // Give the player forward velocity Vector3 moveVector = new Vector3(0, 0, speed); // Move him! rb.velocity = (moveVector * Time.deltaTime); distance = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0)) - transform.position; if (Input.GetMouseButton(0)) { pos = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1)); //pos.x = Mathf.Clamp(pos.x, minX, maxX); //pos.y = Mathf.Clamp(pos.y, minY, maxY); tempP.x = pos.x; tempP.y = pos.y; } transform.position = new Vector3(tempP.x + distance.x / 1.5f, tempP.y + distance.y /1.5f , transform.position.z); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)