zoukankan      html  css  js  c++  java
  • Unity3d C# 创建 物体

    using UnityEngine;
    using System.Collections;
    
    public class create : MonoBehaviour {
    
        // Use this for initialization
        public GameObject newObject;
        
        void OnGUI()
        {
            if(GUI.Button(new Rect(10,10,100,50),"开始"))
            {
                //创建游戏物体
                GameObject instance  = (GameObject)Instantiate(newObject,transform.position,transform.rotation);
                //获取move脚本中的变量run
                GameObject.Find("3rd Person Controller").GetComponent<move>().run=true;
            }
        }
        
    }
    View Code
    using UnityEngine;
    using System.Collections;
    
    public class move : MonoBehaviour {
        
        
        
        public bool run=false;
        float speed =5.0f;
        // Update is called once per frame
        void Update () {
            
            if(run)
            {
                //获取sphere的transform
                Transform tf = GameObject.Find("Sphere").GetComponent<SphereCollider>().transform;
            
            Transform ren = GameObject.Find("3rd Person Controller").GetComponent<CharacterController>().transform;
                
            if(ren.position.x>=tf.position.x)
            {
                   //控制物体移动
                   transform.Translate(Vector3.left,Camera.main.transform);
                   //播放动画
                   animation.Play("run");
            }
            }
        }
    }
    View Code

    查询脚本手册可以参考 unity3d圣典

  • 相关阅读:
    php 计算概率,可以任意添加
    如何绕过浏览器的弹窗拦截机制
    javascript iframe 操作(一)
    视频学习站
    技术博文
    js如何打印对象
    云主机
    cookie小细节
    cookie细节
    实用网址
  • 原文地址:https://www.cnblogs.com/ZJ199012/p/4123527.html
Copyright © 2011-2022 走看看