本文整理汇总了C#中UnityEngine.Ray.GetPoint方法的典型用法代码示例。如果您正苦于以下问题:C# Ray.GetPoint方法的具体用法?C# Ray.GetPoint怎么用?C# Ray.GetPoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.Ray
的用法示例。
在下文中一共展示了Ray.GetPoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GizmoTest
private static void GizmoTest(Transform aTarget, GizmoType aGizmoType)
{
#if UNITY_EDITOR
if (Application.isPlaying)
{
ThirdPersonMotor motor = (ThirdPersonMotor)aTarget.GetComponent<ThirdPersonMotor>();
if (!motor) return;
// debug auto crouch
Vector3 posHead = motor.transform.position + Vector3.up * ((motor.colliderHeight * 0.5f) - motor.colliderRadius);
Ray ray1 = new Ray(posHead, Vector3.up);
Gizmos.DrawWireSphere(ray1.GetPoint((motor.headDetect - (motor.colliderRadius * 0.1f))), motor.colliderRadius * 0.9f);
Handles.Label(ray1.GetPoint((motor.headDetect + (motor.colliderRadius))), "Head Detection");
// debug check trigger action
Vector3 yOffSet = new Vector3(0f, -0.5f, 0f);
Ray ray2 = new Ray(motor.transform.position - yOffSet, motor.transform.forward);
Debug.DrawRay(ray2.origin, ray2.direction * 0.45f, Color.white);
Handles.Label(ray2.GetPoint(0.45f), "Check for Trigger Actions");
// debug stopmove
Ray ray3 = new Ray(motor.transform.position + new Vector3(0, motor.colliderHeight / 3, 0), motor.transform.forward);
Debug.DrawRay(ray3.origin, ray3.direction * motor.stopMoveDistance, Color.blue);
Handles.Label(ray3.GetPoint(motor.stopMoveDistance), "Check for StopMove");
// debug stopmove
Ray ray4 = new Ray(motor.transform.position + new Vector3(0, motor.colliderHeight / 3.5f, 0), motor.transform.forward);
Debug.DrawRay(ray4.origin, ray4.direction * 1f, Color.cyan);
Handles.Label(ray4.GetPoint(1f), "Check for SlopeLimit");
// debug stepOffset
// Ray ray5 = new Ray((motor.transform.position + new Vector3(0, motor.stepOffsetEnd, 0) + motor.transform.forward * ((motor.capsuleCollider).radius + motor.stepOffsetFwd)), Vector3.down);
// Debug.DrawRay(ray5.origin, ray5.direction * (motor.stepOffsetEnd - motor.stepOffsetStart), Color.yellow);
// Handles.Label(ray5.origin, "Step OffSet");
}
#endif
}
示例2: Continue
protected override bool Continue()
{
float single;
float single1 = (float)(HUDIndicator.stepTime - this.startTime);
if (single1 > this.curve[this.curve.length - 1].time)
{
return false;
}
this.material.Set("_AlphaValue", Mathf.Clamp(this.curve.Evaluate(single1), 0.003921569f, 0.996078432f));
if (this.followPoint)
{
Vector3 vector3 = base.transform.position;
Vector3 point = base.GetPoint(HUDIndicator.PlacementSpace.World, this.worldPosition);
if (vector3.z != point.z)
{
Plane plane = new Plane(-base.transform.forward, vector3);
Ray ray = new Ray(point, Vector3.forward);
if (!plane.Raycast(ray, out single))
{
ray.direction = -ray.direction;
point = (!plane.Raycast(ray, out single) ? vector3 : ray.GetPoint(single));
}
else
{
point = ray.GetPoint(single);
}
}
if (point != vector3)
{
base.transform.position = point;
}
}
return true;
}
示例3: drawFloorExample
void drawFloorExample(Vector3 left, Vector3 right, float length)
{
Ray lr = new Ray(left, new Vector3(focusedCamera.transform.forward.x, 0, focusedCamera.transform.forward.z));
Ray rr = new Ray(right, new Vector3(focusedCamera.transform.forward.x, 0, focusedCamera.transform.forward.z));
Vector3 center = (left + right + lr.GetPoint(length) + rr.GetPoint(length)) * 0.25F;
Gizmos.DrawCube(center , new Vector3(Vector3.Distance(left, right), 0.01F, Vector3.Distance(left, lr.GetPoint(length))));
if(displayTextInformation)
Gizmos.DrawIcon(center, "TableTopHeight.png");
}
示例4: drawLineFromCameraPastPoint
void drawLineFromCameraPastPoint(Vector3 v, float length)
{
Ray r = new Ray(v, v - focusedCamera.transform.position);
Gizmos.DrawLine(v, r.GetPoint(length));
if(displayTextInformation)
Gizmos.DrawIcon(r.GetPoint(length), "EdgeOfViewDistance.png");
else
Gizmos.DrawSphere(r.GetPoint(length), 0.02F);
}
示例5: Update
void Update()
{
if(moving == true){
//ray = Camera.main.ScreenPointToRay (Input.mousePosition);
ray = mainCamera.ScreenPointToRay(Input.mousePosition);
//The Object is 14 away from the camera,
Debug.Log(ray.GetPoint(14));
//rigidbody.MovePosition(rigidbody.position + ray.GetPoint(14) * Time.deltaTime);
selfPosition.x = ray.GetPoint(14).x;
selfPosition.y = ray.GetPoint(14).y;
selfPosition.z = 1.1f;
transform.position = selfPosition;
}
}
示例6: Laser
IEnumerator Laser()
{
line.enabled = true;
while (Input.GetButton("Fire1"))
{
Ray rayObj = new Ray(transform.position, transform.forward);
line.SetPosition(0, rayObj.origin);
if (Physics.Raycast(rayObj, out rayHit))
{
line.SetPosition(1, rayHit.point);
// Debug.Log(rayHit.collider.tag);
if (rayHit.collider.tag == "Enemy")
EnemyHit = true;
}
line.SetPosition(1, rayObj.GetPoint(100));
yield return null;
}
line.enabled = false;
}
示例7: Update
// Update is called once per frame
void Update()
{
frame = lp.CurrentFrame;
if (frame.Hands.Count > 0) {
if (frame.Hands.Leftmost.IsLeft) {
righty = frame.Hands.Leftmost;
rfingers = right.fingers;
}
}
if (right.isActiveAndEnabled) {
if (Vector3.Distance (right.GetPalmPosition (), rfingers [0].GetTipPosition ()) > trigger &&
Vector3.Distance (right.GetPalmPosition (), rfingers [1].GetTipPosition ()) > trigger &&
Vector3.Distance (right.GetPalmPosition (), rfingers [2].GetTipPosition ()) < trigger &&
Vector3.Distance (right.GetPalmPosition (), rfingers [3].GetTipPosition ()) < trigger &&
Vector3.Distance (right.GetPalmPosition (), rfingers [4].GetTipPosition ()) < trigger ) {
Debug.Log ("rockgod!!");
rockgod = true;
} else {
rockgod = false;
}
if (rockgod) {
line.enabled = true;
Ray ray = new Ray (rfingers [1].GetTipPosition (), rfingers[1].GetBoneDirection(2));
// Ray ray1 = new Ray (rfingers [4].GetTipPosition (), rfingers [4].GetBoneDirection ());
line.SetPosition (0, ray.origin);
line.SetPosition (1, ray.GetPoint (100));
} else {
line.enabled = false;
}
}
}
示例8: LineCast
private static Vector3 LineCast(Plane plane, Vector3 a, Vector3 b)
{
float dis;
Ray ray = new Ray(a, b-a);
plane.Raycast( ray, out dis );
return ray.GetPoint(dis);
}
示例9: Update
void Update() {
Vector3 forward = RaycastSource.TransformDirection(Vector3.forward);
bool didHit = Physics.Raycast(RaycastSource.position, forward, out hit, MaxDistance, Collidable);
if (ObjectToPosition != null) {
if (didHit) {
ObjectToPosition.transform.position = hit.point;
lastLegalPlane.SetNormalAndPosition(Vector3.up,
new Vector3(0, ObjectToPosition.transform.position.y, 0));
} else {
Ray castRay = new Ray(RaycastSource.transform.position, RaycastSource.transform.forward);
float rayDistance;
if (lastLegalPlane.Raycast(castRay, out rayDistance)) {
ObjectToPosition.transform.position = castRay.GetPoint(rayDistance);
}
}
}
if (UseLineRenderer) {
if (didHit) {
if (Line.gameObject.activeSelf == false) {
Line.gameObject.SetActive(true);
}
Line.SetPosition(0, RaycastSource.transform.position);
Line.SetPosition(1, ObjectToPosition.transform.position);
} else if (Line.gameObject.activeSelf == true)
Line.gameObject.SetActive(false);
}
}
示例10: RaycastSmoke
public static bool RaycastSmoke(Ray ray)
{
if(!CMDropper.smokePool)
{
return false;
}
for(int i = 0; i < CMDropper.smokePool.size; i++)
{
Transform smokeTf = CMDropper.smokePool.GetPooledObject(i).transform;
if(smokeTf.gameObject.activeInHierarchy)
{
Plane smokePlane = new Plane((ray.origin-smokeTf.position).normalized, smokeTf.position);
float enter;
if(smokePlane.Raycast(ray, out enter))
{
float dist = (ray.GetPoint(enter)-smokeTf.position).magnitude;
if(dist < 16)
{
return true;
}
}
}
}
return false;
}
示例11: ScanSpace
void ScanSpace()
{
// в direction переписываем готовые координаты X и Z, идя по радиусу rEnemyScan
pPos = parentObject.transform.position; // отсутп от родителя
Vector3 pos = new Vector3((Mathf.Sin (angle * Mathf.Deg2Rad) * MyContext.stepaside) + pPos.x, transform.position.y, (Mathf.Cos (angle * Mathf.Deg2Rad) * MyContext.stepaside) + pPos.z);
transform.position = pos;
Quaternion rot = Quaternion.Euler(0, angle, 0);
transform.rotation = rot;
locator = new Ray (transform.position, transform.forward);
line.SetPosition (0, locator.origin);
//если во чтото попали
if (Physics.Raycast(transform.position, transform.forward, out hit, MyContext.rEnemyScan))
{
//если попали в игрока, то держим на нём взгляд
if (hit.transform.gameObject.tag == "Player")
{
targetObject = hit.transform.gameObject;
search = false;
return;
}
//иначе обрубаем луч на первом коллаедре
else
line.SetPosition(1, hit.point);
}
//если не попали
else
line.SetPosition(1, locator.GetPoint(MyContext.rEnemyScan));
//прибавляем угол
if (angle >= 359) {angle = 0;} else angle += MyContext.scanSpeed; // скидываем угол на 0 при 359 градусах
}
示例12: Update
void Update()
{
if (null != mirrorPlane) {
if (null != objectBeforeMirror) {
transform.position = objectBeforeMirror.transform.position;
transform.rotation = objectBeforeMirror.transform.rotation;
Vector3 positionInMirrorSpace = mirrorPlane.transform.InverseTransformPoint( objectBeforeMirror.transform.position );
// move camera forward
positionInMirrorSpace.y = -positionInMirrorSpace.y;
positionInMirrorSpace.z = (positionInMirrorSpace.z)/2.5f;
transform.position = mirrorPlane.transform.TransformPoint( positionInMirrorSpace );
/** object is now in correct position, but looking in parallel look direction to original */
/* So, cast a ray from the original object along look-direction until you hit the plane,
* then make the cloned object "look at" that position */
Vector3 mirrorsNormal = mirrorPlane.transform.localRotation * new Vector3( 0f, 1, 0f ); // Unity planes always start with normal pointing up
Plane planeOfMirror = new Plane( mirrorsNormal, mirrorPlane.transform.position );
float intersectionDistance;
Ray rayToMirror = new Ray( objectBeforeMirror.transform.position, objectBeforeMirror.transform.forward );
planeOfMirror.Raycast( rayToMirror, out intersectionDistance );
Vector3 hitPoint = rayToMirror.GetPoint( intersectionDistance );
transform.LookAt( hitPoint );
}
}
}
示例13: FireLaser
IEnumerator FireLaser()
{
line.enabled = true;
gameObject.GetComponent<Light> ().enabled = true;
while (Input.GetButton ("Fire1"))
{
Ray ray = new Ray (transform.position, transform.forward);
RaycastHit hit;
line.SetPosition (0, ray.origin);
if (Physics.Raycast (ray, out hit, 100)) {
line.SetPosition (1, hit.point);
if (hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition (transform.forward * 100, hit.point);
}
}
else
line.SetPosition (1, ray.GetPoint (100));
yield return null;
}
line.enabled = false;
gameObject.GetComponent<Light> ().enabled = false;
}
示例14: ShootELaser
IEnumerator ShootELaser()
{
eLine.enabled = true;
eLine.GetComponent<Renderer>().material.mainTextureOffset = new Vector2(0, Time.time);
Ray ray = new Ray();
ray = eC.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2, 0));
RaycastHit hit;
eLine.SetPosition(0, eShotPoint);
if (Physics.Raycast(ray, out hit, 100))
{
eLine.SetPosition(1, hit.point);
if (hit.collider.tag == "Player")
{
HUD.playerHit = true;
HUD.score -= 100;
}
Instantiate(eLaserParticles, hit.point, eParticleRotation.transform.rotation);
}
else
{
eLine.SetPosition(1, ray.GetPoint(100));
}
eLaserShot = true;
yield return null;
}
示例15: fireLaserOnce
void fireLaserOnce()
{
Ray ray = new Ray (cam.transform.position, cam.transform.forward);
RaycastHit hit;
if (Input.GetButtonDown ("Fire1")) {
line.SetPosition (0, transform.Find ("laserspawn").position);
if (!AddForce)
{
line.enabled = true;
if (Physics.Raycast (ray, out hit, 100)) {
line.SetPosition (1, hit.point);
hit.transform.SendMessage ("damage", dmg, SendMessageOptions.DontRequireReceiver);
} else {
line.SetPosition (1, ray.GetPoint (60));
}
} else {
line.enabled = true;
if (Physics.Raycast (ray, out hit, 100)) {
line.SetPosition (1, hit.point);
if (hit.rigidbody){
hit.rigidbody.AddForceAtPosition(transform.forward * force, hit.point);
Debug.Log("Rigidbody " + hit.transform.gameObject.name + " Hit!");
}
} else {
line.SetPosition (1, ray.GetPoint (60));
}
}
}
if (line.enabled == true){
DestroyTimer(0.05f);
}
}