首页 > 分享 > Unity 宠物跟随效果

Unity 宠物跟随效果

最新推荐文章于 2023-11-10 12:51:18 发布

哒哒咦哒哒·· 于 2018-03-15 15:23:29 发布

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。

下面的案例是实现宠物跟随的效果 
下面的代码是角色移动的脚本

using UnityEngine;

using System.Collections;

public class PlayerMove : MonoBehaviour

{

// Update is called once per frame

void Update () {

//按W键 前进

if (Input.GetKey(KeyCode.W))

{

transform.position += transform.forward * 1 * Time.deltaTime;

}

//按S键 后退

if (Input.GetKey(KeyCode.S))

{

transform.position += transform.forward * -1 * Time.deltaTime;

}

//按A键 向左旋转

if (Input.GetKey(KeyCode.A))

{

transform.Rotate(transform.up, -30 * Time.deltaTime);

}

//按D键 向右旋转

if (Input.GetKey(KeyCode.D))

{

transform.Rotate(transform.up, -30 * Time.deltaTime);

}

}

}

1234567891011121314151617181920212223242526272829

以下是宠物绑定的脚本

using UnityEngine;

using System.Collections;

public class Follow : MonoBehaviour {

public Transform target;

public Vector3 offset;

public float backDistance = 2;

public float topDistance = 2;

void LateUpdate()

{

offset = -target.forward * backDistance + target.up * topDistance;

transform.position = Vector3.Lerp(transform.position, target.position + offset,Time.deltaTime);

transform.rotation = target.rotation;

}

}

相关知识

Unity 宠物跟随效果
宠物跟随效果
使用unity实现桌面宠物
Android全局桌面宠物 Unity方案实现
[Unity]怎么做个桌面宠物精灵desktop mascot
unity自带后期处理插件PostProcess
【Unity后期渲染】Post Processing 后处理插件最全使用说明
男孩桌面小宠物快来玩吧
迷你世界如何让宠物跟随 让宠物跟随方法分享
宠物一键攻击跟随宏 NGA玩家社区

网址: Unity 宠物跟随效果 https://m.mcbbbk.com/newsview319488.html

所属分类:萌宠日常
上一篇: 物业宠物登记表.doc
下一篇: 日常说说