Created
August 10, 2014 01:54
-
-
Save yasuyuki-kamata/afc298742100489516f4 to your computer and use it in GitHub Desktop.
球体をとある範囲で操作する
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class SpherePlayer : MonoBehaviour { | |
public float speed = 5f; | |
public float range = 5f; | |
void Update () { | |
float z = Input.GetAxisRaw ("Vertical"); | |
float x = Input.GetAxisRaw ("Horizontal"); | |
Vector3 direction = new Vector3 (x, 0, z).normalized; | |
transform.Translate (direction * speed * Time.deltaTime); | |
Clamp (); | |
} | |
void Clamp() { | |
Vector3 pos = transform.position; | |
pos.x = Mathf.Clamp (pos.x, -range, range); | |
pos.z = Mathf.Clamp (pos.z, -range, range); | |
transform.position = pos; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment