码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3d C# 创建 物体

时间:2014-11-26 18:09:36      阅读:1166      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   os   sp   for   

bubuko.com,布布扣
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

 

bubuko.com,布布扣
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圣典

Unity3d C# 创建 物体

标签:style   blog   http   io   ar   color   os   sp   for   

原文地址:http://www.cnblogs.com/ZJ199012/p/4123527.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!