Version: 2017.2

Vector3.ClampMagnitude

Cambiar al Manual
public static Vector3 ClampMagnitude (Vector3 vector, float maxLength);

Descripción

Retorna una copia de vector con su magnitud sujeta a maxLength.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour { public Vector3 centerPt; public float radius; void Update() { Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")); Vector3 newPos = transform.position + movement; Vector3 offset = newPos - centerPt; transform.position = centerPt + Vector3.ClampMagnitude(offset, radius); } }