在我的游戏中,我添加了一个简单的游戏对象来跟随我的玩家,但问题是当我单击“播放”时,它并没有显示跟随者,我是新来的团结者,任何人都可以帮助我。不能附加我尝试过的脚本并输出我现在得到的屏幕截图。
(跟随者在场景窗口中可见,当我单击“播放”按钮时消失)
脚本:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FollowPlayer : MonoBehaviour {
public GameObject playerobj ;
public float smoothtime = 0.3f ;
Vector2 velocity = Vector2.zero;
public int yoffset;
void Start () {
}
void Update () {
Vector2 targetPosition = playerobj.transform.TransformPoint(new
Vector3(0,yoffset));
if(targetPosition.y < transform.position.y)
return;
targetPosition = new Vector3(0 , targetPosition.y);
transform.position = Vector2.SmoothDamp(transform.position,targetPosition,ref velocity,smoothtime);
transform.position = new Vector3(transform.position.x ,transform.position.y ,-10) ;
}
}
先谢谢大家!
答案 0 :(得分:0)
您应该检查对象的图层和相机的图层蒙版
答案 1 :(得分:0)
经过大量搜索和参考之后,我终于找到了一个可行的解决方案。 我在更新方法中更改了这些值。希望我的回答对您有所帮助。
void Update () {
Vector2 targetPosition = playerobj.transform.TransformPoint(new Vector3(0,yoffset));
if(targetPosition.y < transform.position.y)
return;
targetPosition = new Vector2(0 , targetPosition.y-8);
transform.position = Vector2.SmoothDamp(transform.position,targetPosition,ref velocity,smoothtime);
transform.position = new Vector2(transform.position.x ,transform.position.y) ;
}