unity照相机跟随
unity控制小球简单移动camera跟随效果
小球移动代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Move : MonoBehaviour {
private Animator m_Animator = null;
// Use this for initialization
void Start () {
m_Animator = GetComponent<Animator>();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.A))
m_Animator.SetInteger("ActionID",1);
if (Input.GetKeyDown(KeyCode.D))
m_Animator.SetInteger("ActionID",0);
}
}
摄像机跟随代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraFollow : MonoBehaviour
{
public GameObject target;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
this.transform.LookAt(target.transform.position);
}
}
小球移动代码绑定到小球上,摄像机跟随代码绑定到需要用到的摄像机上(自己使用的Main Camera)
代码中的target即为此处的目标(指小球)