本文整理汇总了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);
}
示例2: TargetLock
////////////////// CAMERA ////////////////////
public void TargetLock(Vector3 enemyVec)
{
enemyLook = this.transform;
enemyLook.LookAt (enemyVec);
// this.transform.LookAt (enemyVec);
isEnemyLook = true;
}
示例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);
}
示例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);
}
示例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));
}
示例6: Start
void Start()
{
GameObject go = GameObject.FindGameObjectWithTag("Player");
projRB = projectile.GetComponent<Rigidbody2D>();
playerPos = go.transform;
myTranform = GetComponent<Transform>();
myTranform.LookAt(playerPos);
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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");
}
示例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 );
}
示例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>();
}
示例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);
}
示例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);
}