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


C# Transform.LookAt方法代码示例

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


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

示例1: move

        public static void move(Transform transform)
        {
            var velocity = new Vector3();
            var movement = new Vector3();

            var inAirMultiplier = 0.25f;
            var speed = 17f;

            if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.D))
            {
                var z = Input.GetKey(KeyCode.W) ? 1.0f : 0;
                z = Input.GetKey(KeyCode.S) ? -1.0f : z;

                var x = Input.GetKey(KeyCode.D) ? 1.0f : 0;
                x = Input.GetKey(KeyCode.A) ? -1.0f : x;

                movement.z = speed * z;
                movement.x = speed * x;

                //face movement dir
                Vector3 keyboardPosition = new Vector3(x, 0, z);
                transform.LookAt(transform.position + keyboardPosition);
            }

            velocity.y += Physics.gravity.y * Time.deltaTime;
            movement.x *= inAirMultiplier;
            movement.z *= inAirMultiplier;

            movement += velocity;
            movement += Physics.gravity;
            movement *= Time.deltaTime;
            transform.GetComponent<CharacterController>().Move(movement);
        }
开发者ID:hanwang92,项目名称:BAM,代码行数:33,代码来源:move.cs

示例2: TargetLock

 ////////////////// CAMERA ////////////////////
 public void TargetLock(Vector3 enemyVec)
 {
     enemyLook = this.transform;
     enemyLook.LookAt (enemyVec);
     //		this.transform.LookAt (enemyVec);
     isEnemyLook = true;
 }
开发者ID:otani23,项目名称:action,代码行数:8,代码来源:PlayerControll.cs

示例3: Start

 void Start()
 {
     distance = 10;
         camtransf = transform;
         rotatespeed = 1.5f;
         transform.position = new Vector3(camfocuss.transform.position.x,camfocuss.transform.position.y + distance,camfocuss.transform.position.z-5);
         camtransf.LookAt(camfocuss);
 }
开发者ID:C5E3B7BD,项目名称:CryptDuel,代码行数:8,代码来源:camera.cs

示例4: scaleObjectBetween

	private static void scaleObjectBetween(Transform trans, Vector3 pos, Vector3 targetPos) {
		Vector3 scale = trans.localScale;
		Vector3 delta = targetPos - pos;
		scale.z = delta.magnitude;
		trans.localScale = scale;

		trans.position = (targetPos + pos) / 2;
		trans.LookAt(targetPos);
	}
开发者ID:J0eCool,项目名称:MageFox,代码行数:9,代码来源:LightningBullet.cs

示例5: Execute

        public override void Execute() {
			if (FollowUser.Target == null) {
				return;
			}
			myTrans = myTrans == null ? FollowUser.gameObject.transform : myTrans;
			targetTrans = targetTrans == null ? FollowUser.Target.transform : targetTrans;
			myTrans.position = Vector3.Lerp(myTrans.position, FollowUser.wantPos, Time.deltaTime * Mathf.Max (FollowUser.distance, 2));
			myTrans.LookAt ((targetTrans.position + (Vector3.up * 2)) - (FollowUser.wantPos - myTrans.position));
        }
开发者ID:InvertGames,项目名称:uFrame.Photon,代码行数:9,代码来源:LateUpdateFollowUser.cs

示例6: Start

    void Start()
    {
        GameObject go = GameObject.FindGameObjectWithTag("Player");
        projRB = projectile.GetComponent<Rigidbody2D>();
        playerPos = go.transform;

        myTranform = GetComponent<Transform>();
        myTranform.LookAt(playerPos);
    }
开发者ID:danhuynh0803,项目名称:Project-Arena,代码行数:9,代码来源:AimPlayer.cs

示例7: Start

    // Use this for initialization
    void Start()
    {
        myTransform = transform;
        GameObject go = GameObject.FindGameObjectWithTag("Player");
        target = go.transform;
        // rotate the projectile to aim the target:
        myTransform.LookAt(target);

        pause = false;
    }
开发者ID:scvetkovski,项目名称:War-Game,代码行数:11,代码来源:BossBullet.cs

示例8: AddToCollection

	static public void AddToCollection (Transform page)
	{
		float pageRatio = (float)pageList.Count / (float)pageCount;
		float angle = 4f * Mathf.PI * pageRatio;
		float radius = 0.02f + 0.2f * Mathf.Sin(pageRatio * Mathf.PI);
		float height = -0.2f  + pageRatio * 0.4f;
		page.parent = Home.instance.transform;
		page.localPosition = new Vector3(Mathf.Cos(angle) * radius, height, Mathf.Sin(angle) * radius);
		page.LookAt(page.parent);
		pageList.Add(page);
	}
开发者ID:leon196,项目名称:MystJamGame,代码行数:11,代码来源:Home.cs

示例9: Start

    // Use this for initialization
    void Start ()
    {
        canMove = true;
        tpsCamera = transform.GetChild(0);
        tpsCamera.localPosition = startingCameraOffset;
        tpsCamera.LookAt(transform);
        bloodDrip = GetComponent<AudioSource>();
        StartCoroutine("dripBlood");
        myCanvas.alpha = 0f;
        fade = false;
	}
开发者ID:WSquared88,项目名称:GGJ2016,代码行数:12,代码来源:PlayerController.cs

示例10: LookAt

 /// <summary>
 /// Looks at target in 2D
 /// </summary>
 /// <param name=’transform’>
 /// Transform of the rotating object
 /// </param>
 /// <param name=’target’>
 /// Target being looked at
 /// </param>
 /// <param name=’axis’>
 /// Global axis of rotation, a single axis
 /// </param>
 public static void LookAt(Transform transform, Vector3 target, Vector3 axis)
 {
     if(axis == Vector3.up || axis == -Vector3.up){
         target.y = transform.position.y;
     }else if(axis == Vector3.right || axis == -Vector3.right){
         target.x = transform.position.x;
     }else if(axis == Vector3.forward || axis == -Vector3.forward){
         target.z = transform.position.z;
     }
     transform.LookAt(target, axis);
 }
开发者ID:pdcgomes,项目名称:Ziltoidia,代码行数:23,代码来源:Rotation2D.cs

示例11: SetTarget

    public void SetTarget(Transform target, bool isSuccess)
    {
        myTransform = transform;
        shouldHit = isSuccess;
        victim = target;
        myTransform.LookAt(target);

        distance = Vector3.Distance(myTransform.position, target.position);

        StartCoroutine("Move");
    }
开发者ID:RafalWilinski,项目名称:TurnBasedGame_Unity3D,代码行数:11,代码来源:Bullet.cs

示例12: Start

    // Use this for initialization
    public override void Start()
    {
        base.Start();
        refPlayer = ReferenceManager.Player.Trans;

        var newObj = new GameObject( "[ObjectMoveChasePlayer]RotationObject" );
        rotationObject = newObj.transform;
        SyncPlayerPosition();
        rotationObject.LookAt( refPlayer, Vector3.forward );
        rotationObject.rotation *= Quaternion.AngleAxis( -90.0f, Vector3.right );
    }
开发者ID:hiroki-kitahara,项目名称:Shoooooooooooooting-kitahara,代码行数:12,代码来源:ObjectMoveChasePlayer.cs

示例13: Start

    void Start()
    {
        GameObject temp = new GameObject();
        temp.name = "CameraHolderRotation_CalculationsTransform";
        calculationsTransform = temp.transform;

        calculationsTransform.LookAt(targetLookAtTransform, targetLookAtTransform.up);
        transform.rotation = calculationsTransform.rotation;

        creaturePVA = GameObject.FindGameObjectWithTag("MeshCreature").GetComponent<PVA>();
    }
开发者ID:sagarpatel,项目名称:FrequencyDomain,代码行数:11,代码来源:CameraHolderRotation.cs

示例14: AddToCollection

	static public void AddToCollection (Transform tresor)
	{
		float tresorRatio = (float)tresorList.Count / (float)tresorCount;
		float angle = 4f * Mathf.PI * tresorRatio;
		float radius = 0.02f + 0.2f * Mathf.Sin(tresorRatio * Mathf.PI);
		float height = -0.2f  + tresorRatio * 0.4f;
		tresor.parent = Home.instance.transform;
		tresor.localPosition = new Vector3(Mathf.Cos(angle) * radius, height, Mathf.Sin(angle) * radius);
		tresor.LookAt(tresor.parent);
		tresorList.Add(tresor);
	}
开发者ID:leon196,项目名称:TributeToMyst,代码行数:11,代码来源:Home.cs

示例15: Awake

 void Awake()
 {
     camera = GameObject.Find ("Main Camera");
             player = GameObject.Find ("Player");
             playerPos = player.transform.position;
             cameraPos = camera.transform;
             gameTransform = this.gameObject.transform;
             this.gameObject.transform.eulerAngles = new Vector3 (0f, 0f, 0f);
             //this.gameObject.transform.position = new Vector3 (playerPos.x + rightOffset, playerPos.y + heightAbove, playerPos.z - distanceBehind);
             cameraPos.position = new Vector3 (playerPos.x + rightOffset, playerPos.y + heightAbove, playerPos.z + distanceBehind);
             cameraPos.LookAt (player.transform);
 }
开发者ID:Borimir,项目名称:Shammons2,代码行数:12,代码来源:CameraBehavior.cs


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