Version: 2019.3

# Vector3.ProjectOnPlane

public static Vector3 ProjectOnPlane (Vector3 vector, Vector3 planeNormal);

## 参数

 planeNormal 从矢量到平面的方向。 vector 平面上方的矢量的位置。

## 返回

Vector3 平面中的矢量的位置。

## 描述

Vector3 将给定 vector 的位置存储在 3D 空间中。另一个 Vector3planeNormal 提供，用于定义通过原点从平面到 vector 的方向。Vector3.ProjectOnPlane 使用两个 Vector3 值在 planeNormal 方向生成 vector 的位置，并返回 Vector3 在平面上的位置。

```using System.Collections;
using System.Collections.Generic;
using UnityEngine;// Vector3.ProjectOnPlane - example// Generate a random plane in xy. Show the position of a random
// vector and a connection to the plane. The example shows nothing
// in the Game view but uses Update(). The script reference example
// uses Gizmos to show the positions and axes in the Scene.public class Example : MonoBehaviour
{
private Vector3 vector, planeNormal;
private Vector3 response;
private float degrees;
private float timer = 12345.0f;    // Generate the values for all the examples.
// Change the example every two seconds.
void Update()
{
if (timer > 2.0f)
{
// Generate a position inside xy space.
vector = new Vector3(Random.Range(-1.0f, 1.0f), Random.Range(-1.0f, 1.0f), 0.0f);            // Compute a normal from the plane through the origin.
degrees = Random.Range(-45.0f, 45.0f);
response = Vector3.ProjectOnPlane(vector, planeNormal);            // Reset the timer.
timer = 0.0f;
}
timer += Time.deltaTime;
}    // Show a Scene view example.
void OnDrawGizmosSelected()
{
// Left/right and up/down axes.
Gizmos.color = Color.white;
Gizmos.DrawLine(transform.position - new Vector3(2.25f, 0, 0), transform.position + new Vector3(2.25f, 0, 0));
Gizmos.DrawLine(transform.position - new Vector3(0, 1.75f, 0), transform.position + new Vector3(0, 1.75f, 0));        // Display the plane.
Gizmos.color = Color.green;