Unity之API
来源:互联网 发布:如何关闭windows shell 编辑:程序博客网 时间:2024/05/20 22:27
1:场景切换很简单,调用一个函数就可以。
GameObject类的一个成员方法,有两个重载形式,1:gameobject:2:gameobject,float t,t是时间,过t秒销毁 ,本例中的gameobject是脚本挂载的那个游戏对象。
if(hasJumped&&state.IsName("Base Layer.idle"))//处于idle状态,就让场景复原 { hasJumped = false; Application.LoadLevel(0); }
也可以这样:
代码:
using UnityEngine.SceneManagement;
SceneManager.LoadScene("Game");
只是要注意要在buildsetings中将要跳转的场景添加进来、
2:让 物体显示与隐藏
using UnityEngine;using System.Collections;public class test1 : MonoBehaviour { private GameObject cube; private GameObject cube1;void Start () { cube = GameObject.Find("Cubettt"); cube1 = GameObject.Find("sd");}// Update is called once per framevoid Update () { cube1.SetActive(true);//激活cube1,使其显示在场景中 bool active=cube1.activeSelf;//activeSelf返回一个bool值,表示cube1的激活状态 string act = active.ToString();//格式转换 Debug.Log(act);//往控制台打印信息}}
3:往控制台输出信息
Debug.Log("string");
4:设置父物体
gameObject.GetComponent<Transform>().setparent(Transform);
gameObject就成了Transform的子物体。
5:获取子物体组件
Transform.GetComponentInChildren<Transform>(),获得所有子物体的某种组件,当然组件可以有多种
Transform[] abc = hit.collider.gameObject.transform.parent.GetComponentsInChildren<Transform>(); 调用GetComponentsInChildren方法返回的是所有子物体的某种组件。所以得用数组存储,这样就可以操作每一个物体
注意GetComponentsInChildren和GetComponentInChildren有区别。
6:销毁物体
代码:
using UnityEngine; using System.Collections; public class Destroy : MonoBehaviour { private Transform trans; // Use this for initialization void Start () { trans = GetComponent<Transform>(); } void Update() { if (trans.position.y < -1) GameObject.Destroy(gameObject); } }
GameObject类的一个成员方法,有两个重载形式,1:gameobject:2:gameobject,float t,t是时间,过t秒销毁 ,本例中的gameobject是脚本挂载的那个游戏对象。
0 0
- Unity之API
- Unity Api 文档翻译 之Render Texture
- Unity Api翻译之Audio Listener
- Unity API 文档之Audio Source
- Unity API
- Unity API
- UNITY API
- Unity API测试框架
- Unity常用API
- Unity API 笔记
- Unity API - A
- Unity API理解注释
- unity的 Social API
- Unity调用Android API
- Unity API - B
- Unity API - C
- Unity 常用旋转API
- Unity 核心API
- 【BZOJ 3306】树【LCA、DFS序、线段树】
- 我的笔记 Spring+SpringMVC+hibernate整合
- 【JAVA】JDBC编程基础
- 网络编程入门
- Kubernetes 1.5部署安装dashboard
- Unity之API
- caffe训练出错:Error parsing text-format caffe.NetParameter: 10:1: Expected identifier
- 枚举类型
- idea Failed to start component
- codevs1222 二分图匹配
- iOS——Storyboard使用
- PAT(Python)-1020:月饼(25)
- kafka源码分析之一server启动分析
- 欢迎使用CSDN-markdown编辑器