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


C# UnityEngine.Ray类代码示例

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


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

示例1: FollowMouse

		public IEnumerator FollowMouse(GameObject _item)
		{
			Debug.Log("follow mouse started");
			while (Input.GetMouseButton(0) == true)
			{
				float _mouseXR = (Mathf.Round(Input.mousePosition.x * 2)) / 2;
				float _mouseYR = (Mathf.Round(Input.mousePosition.y * 2)) / 2;
				Vector3 _mouseVR = new Vector3(_mouseXR, _mouseYR , 0.0f);
				_item.transform.position = _mouseVR * Time.deltaTime;
			}
			Debug.Log ("Leaving loop");
			Debug.Log ("checking underneath");
			RaycastHit _rayHit;
			Ray _ray = new Ray( _item.transform.position, Vector3.down);
			Debug.Log("did i hit?");
			if (Physics.Raycast(_ray, out _rayHit))
			{
				if (_rayHit.collider.gameObject.tag == "floor")
				{
					_item.transform.position = _rayHit.collider.gameObject.transform.position;
					Debug.Log("yes");
				}
			}
			else 
			{
				Debug.Log ("no");
				DestroyObject(_item);
			}
			yield return null;

		}
开发者ID:mbucher,项目名称:Raid_My_Vault,代码行数:31,代码来源:UI_Events.cs

示例2: OnMouseOver

        void OnMouseOver() // event souris dessus
        {
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            Physics.Raycast(ray, out hit, 100);
            if (Input.GetKeyDown(KeyCode.Mouse0))
            {
                if (!hit.Equals(null))
                {
                    if (hit.collider == myCollider) // Collision clic
                    {
                        // myMenu.update_Color(myColor); 
                        // Change la couleur des valeurs -> est maintenant directement géré depuis le updateValuesPlayer du playerController

                        GetComponent<Transform>().parent.parent.gameObject.GetComponent<BasicPlayerController>().updateValuesPlayer(myColor);
                        /*
						if (PhotonNetwork.inRoom) {
							GetComponent<Transform> ().parent.parent.gameObject.GetComponent<PlayerController> ().updateValuesPlayer (myColor);
						} else {
							GetComponent<Transform>().parent.parent.gameObject.GetComponent<Player_controller>().updateValuesPlayer(myColor);
						}*/
                        transform.localScale -= new Vector3(0.02f, 0.02f, 0.02f);
                    }
                }
            }
            if (Input.GetKeyUp(KeyCode.Mouse0))
            {
                transform.localScale += new Vector3(0.02f, 0.02f, 0.02f);
            }
        }
开发者ID:CanPayU,项目名称:SuperSwungBall,代码行数:29,代码来源:ButtonController.cs

示例3: 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;
		}
开发者ID:tetryds,项目名称:BDArmory,代码行数:27,代码来源:CMSmoke.cs

示例4: 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);
   }
 }
开发者ID:MaTriXy,项目名称:cardboard-unity,代码行数:27,代码来源:RaycastPositioner.cs

示例5: Update

		void Update ()
		{
		
			if (Showtime) {
				if (Time.time >= timeTemp + Delay) {
				
					Ray ray = new Ray (this.transform.position + new Vector3 (Random.Range (-RandomSize, RandomSize), 0, Random.Range (-RandomSize, RandomSize)), -Vector3.up);
					RaycastHit hit;
					if (Physics.Raycast (ray, out hit, 100))
						positionLook = hit.point;

				
					Quaternion look = Quaternion.LookRotation ((positionLook - this.transform.position).normalized);
					look.eulerAngles = new Vector3 (0, look.eulerAngles.y, 0);
					this.transform.rotation = look;
					if (RandomSkill) {
						Index = Random.Range (0, Skills.Length);
					} else {
						Index += 1;
					}
					Deploy ();
					timeTemp = Time.time;	
				}
			} else {
				Aim ();
				if (Input.GetMouseButtonDown(0)) {
					Deploy ();
				}
			}
			KeyUpdate();
		}
开发者ID:Darkchicken,项目名称:SeniorProjectRPG,代码行数:31,代码来源:Wizard.cs

示例6: ClosestPointToRay

        public static Vector2 ClosestPointToRay(Ray ray, Vector2 point)
        {
            //http://pastie.org/1066490
            var t = Vector2.Dot(point - (Vector2) ray.origin, ray.direction);

            return ray.GetPoint(t);
        }
开发者ID:dannisliang,项目名称:GUIHelpers,代码行数:7,代码来源:Helpers2D.cs

示例7: UpdateHeadStability

        /// <summary>
        /// Updates the StableHeadPosition and StableHeadRotation based on GazeSample values.
        /// Call this method with Raycasthit parameters to get stable values.
        /// </summary>
        /// <param name="position">Position value from a RaycastHit point.</param>
        /// <param name="rotation">Rotation value from a RaycastHit rotation.</param>
        public void UpdateHeadStability(Vector3 position, Quaternion rotation)
        {
            Vector3 gazePosition = position;
            Vector3 gazeDirection = rotation * Vector3.forward;

            positionRollingStats.AddSample(gazePosition);
            directionRollingStats.AddSample(gazeDirection);

            float lerpPower = unstabalizedLerpFactor;
            if (positionRollingStats.ActualSampleCount > minimumSamplesRequiredToStabalize && // we have enough samples and...
                (positionRollingStats.CurrentStandardDeviation > positionStandardDeviationReset || // the standard deviation of positions is high or...
                 directionRollingStats.CurrentStandardDeviation > directionStandardDeviationReset)) // the standard deviation of directions is high
            { 
                // We've detected that the user's gaze is no longer fixed, so stop stabalizing so that gaze is responsive.
                //Debug.LogFormat("Reset {0} {1} {2} {3}", positionRollingStats.standardDeviation, positionRollingStats.standardDeviationsAway, directionRollignStats.standardDeviation, directionRollignStats.standardDeviationsAway);
                positionRollingStats.Reset();
                directionRollingStats.Reset();
            }
            else if (positionRollingStats.ActualSampleCount > minimumSamplesRequiredToStabalize)
            {
                // We've detected that the user's gaze is fairly fixed, so start stabalizing.  The more fixed the gaze the less the cursor will move.
                lerpPower = stabalizedLerpBoost * (positionRollingStats.CurrentStandardDeviation + directionRollingStats.CurrentStandardDeviation);
            }

            StableHeadPosition = Vector3.Lerp(StableHeadPosition, gazePosition, lerpPower);
            StableHeadRotation = Quaternion.LookRotation(Vector3.Lerp(StableHeadRotation * Vector3.forward, gazeDirection, lerpPower));
            StableHeadRay = new Ray(StableHeadPosition, StableHeadRotation * Vector3.forward);
        }
开发者ID:Microsoft,项目名称:HoloToolkit-Unity,代码行数:34,代码来源:GazeStabilizer.cs

示例8: Update

        //Calculate the bounce and turn the ball into that direction.
        private void Update()
        {
            Ray ray = new Ray(transform.position, transform.forward);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit, Time.deltaTime * LS_moveSpeed + 0.1f, LS_LayerMask))
            {
                //Show the normal of the plane
                Debug.DrawRay(transform.position, transform.forward);

                //Reflect the electricity
                Vector3 reflectDir = Vector3.Reflect(ray.direction, hit.normal);

                //Calculate the turn of the electricity
                float rot = 90 - Mathf.Atan2(reflectDir.z, reflectDir.x) * Mathf.Rad2Deg;
                transform.eulerAngles = new Vector3(0, rot, 0);

                //Add some moveSpeed
                LS_moveSpeed += 0.5f;
            }

            //Move the player and set the movespeed.
            transform.Translate(Vector3.forward * Time.deltaTime * LS_moveSpeed);
            LS_moveSpeed = Mathf.Clamp(LS_moveSpeed, 3, LS_maxSpeed);
        }
开发者ID:stijndelaruelle,项目名称:glupartygame,代码行数:26,代码来源:LS_Electricity.cs

示例9: Effect

		public override void Effect()
		{
			
			Debug.Log ("EFFECT V !!!");

			Ray ray = new Ray();

			RaycastHit rHit;

			ray.origin = hand.transform.position;
			ray.direction = hand.transform.forward;

			Physics.Raycast (ray, out rHit);

			GameObject lightning = (GameObject)MonoBehaviour.Instantiate(lightningObject);
			
			//lightning.transform.position = (hand.transform.position + rHit.transform.position)/2;

			lightning.transform.position = (hand.transform.position + Vector3.forward * 10)/2;

			lightning.transform.position += Vector3.down * 5;

			//Vector3 pathBetween = rHit.transform.position - hand.transform.position;
			Vector3 pathBetween = Vector3.forward * 100;
			
			lightning.transform.eulerAngles = new Vector3(90,180  + Mathf.Rad2Deg * Mathf.Atan( (float)pathBetween.x / pathBetween.z ),180 );
			
			lightning.transform.localScale = pathBetween.magnitude/80 * Vector3.one;

			MonoBehaviour.Destroy ( lightning , 10f);
		}
开发者ID:avax94,项目名称:RUISHarryPotter,代码行数:31,代码来源:VMagic.cs

示例10: CastRayFromBoundObject

        void CastRayFromBoundObject()
        {
            hits.Clear();

            //CAST RAY
            Vector3 v = boundObject.position;
            Quaternion q = boundObject.rotation;
            ray = new Ray(v, q * Vector3.forward);
            hits.AddRange(Physics.RaycastAll(ray, interactDistance));
            eventData.previousRaycast = eventData.currentRaycast;

            if (hits.Count == 0) {
                eventData.currentRaycast = null;
                return;
            }

            //FIND THE CLOSEST OBJECT
            RaycastHit minHit = hits[0];
            for (int i = 0; i < hits.Count; i++) {
                if (hits[i].distance < minHit.distance) {
                    minHit = hits[i];
                }
            }

            //MAKE SURE CLOSEST OBJECT IS INTERACTABLE
            if (interactTag != null && interactTag.Length > 1 && !minHit.transform.tag.Equals(interactTag)) {
                eventData.currentRaycast = null;
                return;
            } else {
                eventData.currentRaycast = minHit.transform.gameObject;
            }
        }
开发者ID:nyu-vr-research,项目名称:vr-platform3,代码行数:32,代码来源:WiiMoteModule.cs

示例11: DropToNearestFloor

        private void DropToNearestFloor(bool withBlink)
        {
            if (enableTeleport && eyeCamera.transform.position.y > this.transform.position.y)
            {
                //send a ray down to find the closest object to stand on
                Ray ray = new Ray(eyeCamera.transform.position, -transform.up);
                RaycastHit rayCollidedWith;
                bool rayHit = Physics.Raycast(ray, out rayCollidedWith);
                float floorY = eyeCamera.transform.position.y - rayCollidedWith.distance;

                if (rayHit && ValidLocation(rayCollidedWith.transform) && !FloorIsGrabbedObject(rayCollidedWith) && (MeshYChanged(rayCollidedWith, floorY) || CurrentFloorChanged(rayCollidedWith)))
                {
                    currentFloor = rayCollidedWith.transform.gameObject;
                    currentRayDownY = floorY;

                    if (withBlink && !rayCollidedWith.transform.GetComponent<MeshCollider>())
                    {
                        Blink(blinkTransitionSpeed);
                    }

                    Vector3 newPosition = new Vector3(this.transform.position.x, floorY, this.transform.position.z);
                    var teleportArgs = new DestinationMarkerEventArgs
                    {
                        destinationPosition = newPosition,
                        distance = rayCollidedWith.distance,
                        enableTeleport = true,
                        target = currentFloor.transform
                    };
                    OnTeleporting(gameObject, teleportArgs);
                    SetNewPosition(newPosition, currentFloor.transform);
                    OnTeleported(gameObject, teleportArgs);
                }
            }
        }
开发者ID:xiaopanCode,项目名称:SteamVR_Unity_Toolkit,代码行数:34,代码来源:VRTK_HeightAdjustTeleport.cs

示例12: Update

        private void Update()
        {
            InteractionText.text = "";

            RaycastHit hit;
            var cam = UnityEngine.Camera.main.transform;
            var forward = cam.forward;
            var position = cam.position;

            var ray = new Ray(position, forward);

            if (Physics.Raycast(ray, out hit))
            {
                var interaction = hit.collider.GetComponent<IInteractable>();
                if (interaction != null && Vector3.Distance(transform.position, hit.collider.transform.position) < InteractionDistance)
                {
                    if (Input.GetKeyDown(KeyCode.E))
                    {
                        interaction.Interact();
                    }
                    else
                    {
                        InteractionText.text = "Press E to interact";
                    }
                }
            }
        }
开发者ID:EricFreeman,项目名称:DungeonGame,代码行数:27,代码来源:PlayerInteractions.cs

示例13: Start

        public override void Start()
        {
            currentTime = 0.0f;
            Enemy enemy = components.action_target.GetComponent<Enemy>();
            Collider2D[] hazards = Physics2D.OverlapCircleAll(enemy.transform.position, fieldOfReaction, 4096);

            for (int i = 0; i < hazards.Length; i++)
            {
                Vector3 hazardPosition = hazards[i].transform.position;
                Vector3 delta = hazardPosition - enemy.transform.position;

                Vector3 optionA = Vector3.Cross(Vector3.forward, delta); optionA = optionA.normalized;
                Vector3 optionB = Vector3.Reflect(optionA, delta); optionB = optionB.normalized;
                Vector3 optionC = delta * -1; optionC = optionC.normalized;

                Vector2[] options = new Vector2[] { optionA, optionB, optionC };

                for (int c = 0; c < options.Length; c++)
                {
                    Ray ray = new Ray(enemy.transform.position, options[c].normalized);
                    RaycastHit2D hit = Physics2D.GetRayIntersection(ray, speed, 256);
                    if (hit)
                    {
                        if (hit.distance < speed * 0.8f) continue;

                        enemy.Impulse(options[c].normalized, speed);
                    }
                    else
                    {
                        enemy.Impulse(options[c].normalized, speed);
                    }
                }
            }
        }
开发者ID:xCosmix,项目名称:Random_Project,代码行数:34,代码来源:EnemyActions.cs

示例14: FixedUpdate

        void FixedUpdate()
        {
            float fmotion = -InputManager.Instance.GetAxis("DEDH_FMotion" + _PlayerID);
            float smotion = InputManager.Instance.GetAxis("DEDH_RMotion" + _PlayerID);

            _RBody.drag = _Drag;
            _RBody.angularDrag = _ADrag;

            _RTorque = _RTorque - (_RBody.velocity.magnitude / 300);
            _RTorque += 1;
            _RTorque = Mathf.Clamp(_RTorque, 1, 5);

            _RBody.AddForce(fmotion * (_MForce - 40 - _RBody.velocity.magnitude) * transform.forward);
            _RBody.AddTorque(smotion * _RTorque * Vector3.up);

            RaycastHit hit;
            Ray dray = new Ray(transform.position, -Vector3.up);

            if (Physics.Raycast(dray, out hit))
            {
                if (hit.transform.tag == "Tag 4")
                {
                    float hoverError = _HHeight - hit.distance;
                    if (hoverError > 0)
                    {
                        float upwardSpeed = _RBody.velocity.y;
                        float lift = hoverError * _HForce - upwardSpeed * _HDamp;
                        _RBody.AddForce(lift * new Vector3(0, 90, 0));
                    }
                }
            }
        }
开发者ID:stijndelaruelle,项目名称:glupartygame,代码行数:32,代码来源:Horsemovement.cs

示例15: CheckAlignment

        private IEnumerator CheckAlignment()
        {
            // Continue looping until the game is no longer running.
            while (m_IsGameRunning)
            {
                // If there is a current ring, set it to be unaligned by default.
                if (m_CurrentRing)
                    m_CurrentRing.ShipAligned = false;

                // Create a ray forward from the flyer's current position.
                Ray ray = new Ray (transform.position, Vector3.forward);
                RaycastHit hit;

                // Spherecast along the ray.
                if (Physics.SphereCast (ray, m_Radius, out hit))
                {
                    // Try to find a ring on the hit object.
                    Ring ring = hit.transform.GetComponent<Ring> ();

                    // If it is a ring...
                    if (ring)
                    {
                        // ...  set it as the current ring and the flyer is aligned with it.
                        m_CurrentRing = ring;
                        m_CurrentRing.ShipAligned = true;
                    }
                }

                // Wait until next frame.
                yield return null;
            }
        }
开发者ID:pemami4911,项目名称:V-RAVE,代码行数:32,代码来源:FlyerAlignmentChecker.cs


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