微信登录

C# - 物体的禁用和启用 - SetActive(false)

作用:代码控制是否显示.SetActive(false);

代码

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class shoot : MonoBehaviour
  5. {
  6. public GameObject B;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. GameObject a = GameObject.Instantiate(B);//实例化
  11. GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);
  12. b.SetActive(false);
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. }
  18. }

代码解释

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class shoot : MonoBehaviour
  5. {
  6. public GameObject B;
  7. // Start is called before the first frame update
  8. void Start()
  9. {
  10. GameObject a = GameObject.Instantiate(B);//实例化
  11. GameObject b = GameObject.Instantiate(B,transform.position,transform.rotation);
  12. b.SetActive(false);//隐藏b
  13. }
  14. // Update is called once per frame
  15. void Update()
  16. {
  17. }
  18. }