找回密码
 立即注册
查看: 319|回复: 0

Unity根据是否可见设置物体是否使用

[复制链接]
发表于 2021-12-30 20:16 | 显示全部楼层 |阅读模式
using UnityEngine;
using System.Collections;

public class VisibleRange : MonoBehaviour {

    public GameObject _Target;

    public static Transform VisibleRoot;

    string m_StartName;

    void Start ( ) {

        m_StartName = name;
        if ( !VisibleRoot ) VisibleRoot = new GameObject( "Visible Root" ).transform;
        if ( _Target ) _Target = transform.parent.gameObject;
        transform.parent = VisibleRoot;

        if ( !renderer.isVisible )
            _Target.SetActive( false );

        if ( renderer.isVisible )
            name = "( 0 0 )   " + m_StartName;
        else
            name = "( -  - )   " + m_StartName;

    }

    void OnBecameVisible ( ) {

        if ( _Target )
            _Target.SetActive( true );

        if ( renderer.isVisible )
            name = "( 0 0 )   " + m_StartName;
        else
            name = "( -  - )   " + m_StartName;
    }

    void OnBecameInvisible ( ) {

        if ( _Target )
            _Target.SetActive( false );

        if ( renderer.isVisible )
            name = "( 0 0 )   " + m_StartName;
        else
            name = "( -  - )   " + m_StartName;
    }

    void OnDrawGizmosSelected ( ) {
        Gizmos.color = Color.yellow;
        Gizmos.DrawWireCube( renderer.bounds.center , renderer.bounds.size );
    }
懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Unity开发者联盟 ( 粤ICP备20003399号 )

GMT+8, 2024-9-22 23:22 , Processed in 0.116002 second(s), 25 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表