您的位置:首页 > 移动开发 > Unity3D

Unity5.x制作合金弹头(四)-相机的跟随

2016-11-25 18:30 323 查看
游戏源码下载

进入下载

在主角移动时,相机需要跟随主角

本节简单,直接贴上代码using UnityEngine;
using System.Collections;
using DG.Tweening;

public class CameraForllow : MonoBehaviour
{
private Transform playerTransform;

// Use this for initialization
void Start()
{
playerTransform = GameObject.FindGameObjectWithTag("Player").transform;
}

// Update is called once per frame
void Update()
{
float offset_x = playerTransform.position.x - transform.position.x;
if (offset_x > 5f && transform.position.x != 40f)
{
transform.DOLocalMoveX(transform.position.x + 10f, 1.5f);
if (transform.position.x == 30f)
transform.DOLocalMoveY(5, 1f);
}
}
}添加头文件:DG.Tweening
transform.DOLocalMoveX函数用于在X轴方向移动相机到指定位置

当相机移动到X轴位置坐标为30.0f时,由于背景地图原因,将上移一个单位
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  unity 合金弹头