简体   繁体   English

游戏对象在游戏视图中不可见

[英]Game object not visible in game view

in my game i added a simple game object to follow my player , but the problem is it is not showing the follower when i click play , i'm new to unity , can any one help me . 在我的游戏中,我添加了一个简单的游戏对象来跟随我的玩家,但问题是当我点击播放时,它并没有显示跟随者,我是团结新手,任何人都能帮助我。 ill be attaching the script that i tried and output screenshot that i'm getting now. 请附加我尝试过的脚本并输出我现在获取的屏幕截图。

(the follower is visible in scene window , disappears when i click play button) (该跟随者在场景窗口中可见,当我单击“播放”按钮时消失)

在此处输入图片说明

script : 脚本:

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) ;

}
}

thanks in advance guys ! 在此先感谢大家!

您应该检查对象的图层和相机的图层蒙版

after doing so many search and reference i finally got a working solution. 经过大量的搜索和参考之后,我终于得到了一个可行的解决方案。 i changed these values in update method. 我在更新方法中更改了这些值。 hope my answer helps some one. 希望我的回答对您有所帮助。

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) ;

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM