当前位置: 首页>>代码示例>>C#>>正文


C# Plane.Raycast方法代码示例

本文整理汇总了C#中UnityEngine.Plane.Raycast方法的典型用法代码示例。如果您正苦于以下问题:C# Plane.Raycast方法的具体用法?C# Plane.Raycast怎么用?C# Plane.Raycast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.Plane的用法示例。


在下文中一共展示了Plane.Raycast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetVanishingPoint

    // =============================================================================
    // METHODS STATIC --------------------------------------------------------------
    public static void SetVanishingPoint( Camera cam, float offset, ClientCameraScreen screen )
    {
        Transform t = cam.transform;
        NearPlane plane = new NearPlane();

        Vector3 nearCenter = t.position + t.forward*cam.nearClipPlane;
        Plane nearPlane = new Plane ( -t.forward, nearCenter );
        float distance = 0f;
        Vector3 direction;
        Ray ray;

        Vector3 screenTL = t.TransformPoint ( new Vector3 ( ( -screen.Width/2.0f ) + offset, screen.Height/2.0f, screen.Distance ) );
        direction = ( screenTL - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearTL = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        Vector3 screenBR = t.TransformPoint ( new Vector3 ( ( screen.Width/2.0f ) + offset, -screen.Height/2.0f, screen.Distance ) );
        direction = ( screenBR - t.position ).normalized;
        ray = new Ray ( t.position, direction );
        nearPlane.Raycast ( ray, out distance );
        Vector3 nearBR = -( t.InverseTransformPoint ( nearCenter ) - t.InverseTransformPoint ( ( t.position + direction*distance ) ) );

        plane.left = nearTL.x;
        plane.top = nearTL.y;
        plane.right = nearBR.x;
        plane.bottom = nearBR.y;
        plane.near = cam.nearClipPlane;
        plane.far = cam.farClipPlane;
        cam.projectionMatrix = PerspectiveOffCenter ( plane );
    }
开发者ID:Jonas90,项目名称:iss,代码行数:33,代码来源:ClientCameraVanishingPoint.cs

示例2: Update

    void Update()
    {
        // Movement Input
        Vector3 moveInput = new Vector3(Input.GetAxisRaw("Horizontal"), 0, Input.GetAxisRaw("Vertical"));
        Vector3 moveVelocity = moveInput.normalized * moveSpeed;

        pc.Move(moveVelocity);

        // Look/Aim Input
        Ray ray = cam.ScreenPointToRay(Input.mousePosition);
        Plane groundPlane = new Plane(Vector3.up, Vector3.zero);

        float rayDist;

        if(groundPlane.Raycast(ray, out rayDist))
        {
            Vector3 point = ray.GetPoint(rayDist);
            Debug.DrawLine(ray.origin, point, Color.red);
            pc.LookAt(point);
        }

        // Shooting Input
        if(Input.GetMouseButton(0))
        {
            gc.Shoot();
        }
    }
开发者ID:gholaday,项目名称:Project-Arena,代码行数:27,代码来源:Player.cs

示例3: DoClick

 private void DoClick(object sender, ClickedEventArgs e)
 {
     if (this.teleportOnClick)
     {
         float y = this.reference.position.y;
         Plane plane = new Plane(Vector3.up, -y);
         Ray ray = new Ray(base.transform.position, base.transform.forward);
         bool flag = false;
         float d = 0f;
         if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
         {
             TerrainCollider component = Terrain.activeTerrain.GetComponent<TerrainCollider>();
             RaycastHit raycastHit;
             flag = component.Raycast(ray, out raycastHit, 1000f);
             d = raycastHit.distance;
         }
         else if (this.teleportType == SteamVR_Teleporter.TeleportType.TeleportTypeUseCollider)
         {
             RaycastHit raycastHit2;
             Physics.Raycast(ray, out raycastHit2);
             d = raycastHit2.distance;
         }
         else
         {
             flag = plane.Raycast(ray, out d);
         }
         if (flag)
         {
             Vector3 position = ray.origin + ray.direction * d - new Vector3(this.reference.GetChild(0).localPosition.x, 0f, this.reference.GetChild(0).localPosition.z);
             this.reference.position = position;
         }
     }
 }
开发者ID:GameDiffs,项目名称:TheForest,代码行数:33,代码来源:SteamVR_Teleporter.cs

示例4: DragObject

    IEnumerator DragObject(float distance)
    {
        var oldDrag = springJoint.connectedBody.drag;
        var oldAngularDrag = springJoint.connectedBody.angularDrag;
        springJoint.connectedBody.drag = drag;
        springJoint.connectedBody.angularDrag = angularDrag;
        var mainCamera = FindCamera();
        while (Input.GetMouseButton (0))
        {
            Plane plane = new Plane(Vector3.back, constraintPlaneObject.transform.position);
            Ray ray = mainCamera.ScreenPointToRay (Input.mousePosition);
            float constraintPlaneDistance = 0.0f;
            plane.Raycast(ray, out constraintPlaneDistance);

            springJoint.transform.position = ray.GetPoint(constraintPlaneDistance);
            line.SetPosition(0, springJoint.transform.TransformPoint(springJoint.anchor));
            line.SetPosition(1, springJoint.transform.position);

            yield return null;
        }
        if (springJoint.connectedBody)
        {
            springJoint.connectedBody.drag = oldDrag;
            springJoint.connectedBody.angularDrag = oldAngularDrag;
            springJoint.connectedBody.freezeRotation = false;
            //springJoint.connectedBody = null;
            Destroy(go);
        }
    }
开发者ID:ZelimDamian,项目名称:Chem,代码行数:29,代码来源:ConstrainedDrag.cs

示例5: Update

	void Update () {
		// Movement input
		Vector3 moveInput = new Vector3 (Input.GetAxisRaw ("Horizontal"), 0, Input.GetAxisRaw ("Vertical"));
		Vector3 moveVelocity = moveInput.normalized * moveSpeed;
		controller.Move (moveVelocity);

		// Look input
		Ray ray = viewCamera.ScreenPointToRay (Input.mousePosition);
		Plane groundPlane = new Plane (Vector3.up, Vector3.up * gunController.GunHeight);
		float rayDistance;

		if (groundPlane.Raycast(ray,out rayDistance)) {
			Vector3 point = ray.GetPoint(rayDistance);
			//Debug.DrawLine(ray.origin,point,Color.red);
			controller.LookAt(point);
			crosshairs.transform.position = point;
			crosshairs.DetectTargets(ray);
			if ((new Vector2(point.x, point.z) - new Vector2(transform.position.x, transform.position.z)).sqrMagnitude > 1) {
				gunController.Aim(point);
			}
		}

		// Weapon input
		if (Input.GetMouseButton(0)) {
			gunController.OnTriggerHold();
		}
		if (Input.GetMouseButtonUp(0)) {
			gunController.OnTriggerRelease();
		}
		if (Input.GetKeyDown (KeyCode.R)) {
			gunController.Reload();
		}
	}
开发者ID:ardaWill,项目名称:Create-a-Game-Source,代码行数:33,代码来源:Player.cs

示例6: OnMouseMove

    public void OnMouseMove( dfControl control, dfMouseEventArgs args )
    {
        if( animating || !dragging )
            return;

        this.momentum = ( momentum + args.MoveDelta.Scale( 1, -1 ) ) * 0.5f;

        args.Use();

        if( args.Buttons.IsSet( dfMouseButtons.Left ) )
        {

            var ray = args.Ray;
            var distance = 0f;
            var direction = Camera.main.transform.TransformDirection( Vector3.back );
            var plane = new Plane( direction, lastPosition );
            plane.Raycast( ray, out distance );

            var pos = ( ray.origin + ray.direction * distance ).Quantize( control.PixelsToUnits() );
            var offset = pos - lastPosition;

            var transformPos = ( control.transform.position + offset ).Quantize( control.PixelsToUnits() );
            control.transform.position = transformPos;

            lastPosition = pos;

        }
    }
开发者ID:dashqasar,项目名称:GoogleMap,代码行数:28,代码来源:TouchThrow.cs

示例7: Update

	void Update()
	{
		var plane = new Plane(Vector3.up, transform.position);
		var ray = Camera.main.ScreenPointToRay(Input.mousePosition);
		float hit;
		if (plane.Raycast(ray, out hit))
		{
			var aimDirection = Vector3.Normalize(ray.GetPoint(hit) - transform.position);
			var targetRotation = Quaternion.LookRotation(aimDirection);
			transform.rotation = Quaternion.RotateTowards(transform.rotation, targetRotation, 360 * Time.deltaTime);

			if (Input.GetMouseButtonDown(0))
				bulletPrefab.Spawn(gun.position, gun.rotation);
		}

		if (Input.GetKeyDown(KeyCode.Space))
		{
			bulletPrefab.DestroyPooled();
		}

		if (Input.GetKeyDown(KeyCode.Z))
		{
			bulletPrefab.DestroyAll();
		}
	}
开发者ID:vietha9119,项目名称:ZigZag,代码行数:25,代码来源:Turret.cs

示例8: Caminar

    void Caminar()
    {
        // Da seguimiento a la distancia entre este gameObject y posicionDestino.
        distanciaDestino = Vector3.Distance(posicionDestino, esteTransform.position);

        // Mueve al jugador si el click izquierdo del mouse fue clickeado.
        if (Input.GetMouseButtonDown(0) && GUIUtility.hotControl == 0) {
            Plane planoJugador = new Plane(Vector3.up, esteTransform.position);
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            //Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
            float longitudRayo = 0.0f;

            // Obtenemos la longitud del rayo.
            if (planoJugador.Raycast(ray, out longitudRayo)) {

                posicionDestino = ray.GetPoint(longitudRayo); // Coordenada destino
                Quaternion rotacionDestino = Quaternion.LookRotation(posicionDestino - transform.position);
                esteTransform.rotation = rotacionDestino;
            }
        }

        // Evita que el codigo se ejecute si no es necesario.
        if(distanciaDestino > .5f){
            esteTransform.position = Vector3.MoveTowards(esteTransform.position, posicionDestino, velocidad * Time.deltaTime);
        }
    }
开发者ID:racsoraul,项目名称:COMPDES_2015,代码行数:26,代码来源:PersonajeArmaMovement.cs

示例9: ConvertScreenToWorld

    // ConvertScreenToWorld //
    // Converts Vector3's from screen to world space - by raycasting from the passed camera //
    // to a plane parallel to the camera, outputs an array of 2 Vector3's                   //
    public static Vector3[] ConvertScreenToWorld( Vector3 point_a, Vector3 point_b, Vector3 position, Camera camera )
    {
        // Convert screen touches into rays from main camera
        Ray ray_a = camera.ScreenPointToRay( point_a );
        Ray ray_b = camera.ScreenPointToRay( point_b );

        // Create a plane parallel to camera, facing the screen - then rotated by the cameras y rotation
        Vector3 parallel_to_camera = RotateY( new Vector3( 0, 0, -1 ), camera.transform.rotation.y );
        Plane plane = new Plane( parallel_to_camera, position );

        // Hit distances
        float hit1;
        float hit2;

        // Hit point Vector3's
        Vector3 hit_point_a = Vector3.zero;
        Vector3 hit_point_b = Vector3.zero;

        // Shoot ray_a at plane
        if( plane.Raycast( ray_a, out hit1 ) )
        {
            // Get where ray_a collides with the plane
            hit_point_a = ray_a.GetPoint( hit1 );
        }

        // Shoot ray_b at plane
        if( plane.Raycast( ray_b, out hit2 ) )
        {
            // Get where ray_b collides with the plane
            hit_point_b = ray_b.GetPoint( hit2 );
        }

        // Return two vectors as array
        return new Vector3[ 2 ] { hit_point_a, hit_point_b };
    }
开发者ID:tomob95,项目名称:Portfolio,代码行数:38,代码来源:TiCuttingUtilities.cs

示例10: 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;
 }
开发者ID:HexHash,项目名称:LegacyRust,代码行数:34,代码来源:HUDHitIndicator.cs

示例11: Update

    void Update()
    {
        Plane plane = new Plane(Vector3.up, 0.0f);

        if (Input.GetMouseButtonDown(0))
        {
          Ray ray = camera.ScreenPointToRay(Input.mousePosition);
          float distance = 0.0f;
          plane.Raycast(ray, out distance);

          mBaseAim   = mAim;
          mBasePoint = ray.GetPoint(distance);
        }

        if (Input.GetMouseButton(0))
        {
          SetAim(mBaseAim, mRotation, mDistance);

          Ray ray = camera.ScreenPointToRay(Input.mousePosition);
          float distance = 0.0f;
          plane.Raycast(ray, out distance);

          Vector3 newPoint = ray.GetPoint(distance);

          SetAim(mBaseAim + mBasePoint - newPoint, mRotation, mDistance);
        }
        else
        if (Input.GetMouseButton(1))
        {
          mRotation.y = mRotation.y + 1.0f;

          SetAim(mAim, mRotation, mDistance);
        }
    }
开发者ID:vachome,项目名称:estate,代码行数:34,代码来源:MouseCameraControl.cs

示例12: DrawLineBetweenWorldPositions

        public static void DrawLineBetweenWorldPositions(Vector3 worldPosA, Vector3 worldPosB, float width, Color color)
        {
            Camera cam = GetMainCamera();
            GUI.matrix = Matrix4x4.identity;

            bool aBehind = false;

            Plane clipPlane = new Plane(cam.transform.forward, cam.transform.position + cam.transform.forward * 0.05f);

            if(Vector3.Dot(cam.transform.forward, worldPosA-cam.transform.position) < 0)
            {
                Ray ray = new Ray(worldPosB, worldPosA - worldPosB);
                float dist;
                if(clipPlane.Raycast(ray, out dist))
                {
                    worldPosA = ray.GetPoint(dist);
                }
                aBehind = true;
            }
            if(Vector3.Dot(cam.transform.forward, worldPosB-cam.transform.position) < 0)
            {
                if(aBehind) return;

                Ray ray = new Ray(worldPosA, worldPosB - worldPosA);
                float dist;
                if(clipPlane.Raycast(ray, out dist))
                {
                    worldPosB = ray.GetPoint(dist);
                }
            }

            Vector3 screenPosA = cam.WorldToViewportPoint(worldPosA);
            screenPosA.x = screenPosA.x*Screen.width;
            screenPosA.y = (1-screenPosA.y)*Screen.height;
            Vector3 screenPosB = cam.WorldToViewportPoint(worldPosB);
            screenPosB.x = screenPosB.x*Screen.width;
            screenPosB.y = (1-screenPosB.y)*Screen.height;

            screenPosA.z = screenPosB.z = 0;

            float angle = Vector2.Angle(Vector3.up, screenPosB - screenPosA);
            if(screenPosB.x < screenPosA.x)
            {
                angle = -angle;
            }

            Vector2 vector = screenPosB - screenPosA;
            float length = vector.magnitude;

            Rect upRect = new Rect(screenPosA.x - (width / 2), screenPosA.y-length, width, length);

            GUIUtility.RotateAroundPivot(-angle+180, screenPosA);
            DrawRectangle(upRect, color);
            GUI.matrix = Matrix4x4.identity;
        }
开发者ID:gomker,项目名称:BDArmory,代码行数:55,代码来源:BDGUIUtils.cs

示例13: Awake

 private void Awake()
 {
     //			Debug.Log ("!!!!!????");
     sky_ = new Plane(Vector3.forward, _z);
     Ray ray1 = _camera.ScreenPointToRay (new Vector3 (0, 0, 0));
     Ray ray2 = _camera.ScreenPointToRay (new Vector3 (0, Screen.height, 0));
     float dist1 = 0;
     sky_.Raycast (ray1, out dist1);
     float dist2 = 0;
     sky_.Raycast (ray2, out dist2);
     y_ = (ray2.GetPoint (dist2) - ray1.GetPoint (dist1)).y;
 }
开发者ID:gdgeek,项目名称:fly,代码行数:12,代码来源:BGLayer.cs

示例14: ConvertDragToWorldSpace

    // Converts mouse coords to world coords
    private void ConvertDragToWorldSpace( Vector3 dragStartPos, Vector3 dragEndPos, out Vector3 dragStartWorld, out Vector3 dragEndWorld )
    {
        Ray dragStartRay = Camera.main.ScreenPointToRay( dragStartPos );
        Ray dragEndRay = Camera.main.ScreenPointToRay( dragEndPos );

        Plane groundPlane = new Plane( Vector3.up, 0 );
        float dist = 0f;
        groundPlane.Raycast( dragStartRay, out dist );
        dragStartWorld = dragStartRay.GetPoint( dist );
        groundPlane.Raycast( dragEndRay, out dist );
        dragEndWorld = dragEndRay.GetPoint( dist );
    }
开发者ID:ZachHoefler,项目名称:RTSControls,代码行数:13,代码来源:UnitSelectionManager.cs

示例15: Update

 // Update is called once per frame
 void Update()
 {
     Plane targetPlane = new Plane(transform.up, transform.position);
     foreach (Touch touch in Input.touches) {
         anim.SetBool("isWalking",true);
         //Gets the ray at position where the screen is touched
         Ray ray = Camera.main.ScreenPointToRay(touch.position);
         //Gets the position of ray along plane
         float dist = 0.0f;
         //Intersects ray with the plane. Sets dist to distance along the ray where intersects
         targetPlane.Raycast(ray, out dist);
         //Returns point dist along the ray.
         Vector3 planePoint = ray.GetPoint(dist);
         //Debug.Log("Point=" + planePoint);
         //True if finger touch began. If ray intersects collider, set pickedObject to transform
         //of collider object
         if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Stationary) {
             //anim.SetBool("isWalking",true);
             player.transform.LookAt(planePoint);
             player.transform.localPosition = Vector3.MoveTowards(playerPos, planePoint, 0.5F * Time.deltaTime);
             //playerPos = player.transform.position;
             playerPos = player.transform.localPosition;
         } else if (touch.phase == TouchPhase.Ended){
             anim.SetBool("isWalking",false);
         }
     }
 }
开发者ID:nuttonutto,项目名称:Demo,代码行数:28,代码来源:clickedMove.cs


注:本文中的UnityEngine.Plane.Raycast方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。