Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- [RequireComponent (typeof(Rigidbody))]
- public class MovingTest : MonoBehaviour {
- [SerializeField] float moveSpeed = 10f;
- [SerializeField] bool a = true;
- Transform trans;
- Rigidbody rig;
- void Awake()
- {
- trans = transform;
- rig = rigidbody;
- }
- void Update()
- {
- float moveHorizontal = Input.GetAxis("Horizontal");
- float moveVertical = Input.GetAxis("Vertical");
- rig.velocity = new Vector3(moveHorizontal * moveSpeed, 0, moveVertical * moveSpeed);
- if (a)
- {
- rig.position = new Vector3
- (
- Mathf.Clamp(rig.position.x, -1, 1),
- 0.0f,
- Mathf.Clamp(rig.position.z, 0, 10)
- );
- }
- else
- {
- trans.localPosition = new Vector3
- (
- Mathf.Clamp(trans.localPosition.x, -1, 1),
- 0.0f,
- Mathf.Clamp(trans.localPosition.z, 0, 10)
- );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement