UNITY 基础API

using UnityEngine;
using System.Collections;


using UnityEngine.SceneManagement ; 


public class API_07Vector : MonoBehaviour {
//Vector2  v = Input.mousePosition; // 1000 -900 像素,   --像素是一个长度单位,,一个位置
// 结构体,---使用, Vector 2 
// 修改位置, 
// 值类型, 没有对象的啊啊啊   不能对象点 字段啊啊啊
//transform.position  = new Vector3 (0,0,0);  //dui 
//transform.position.x  = 10 ;   // 对象 cuo 


//---------------------------------- 不能通过对象赋值, 但可以通过结构体,给赋值
// Vector3 pos = transform.position;  // 
// pos.x = 10;  // ????????? 这为啥可??????????????????????????
// transform.position = pos;

// Use this for initialization






// Stream Assest ---资源不会压缩,其他会压缩,路径啥都不会改变   音频视屏 AssestBudoule 
// 资源不会合并,


public Transform p;
public Transform enemy;
void Start () {
 
// Vector3 a = new Vector3 (0,0,1);
// Vector3 b = new Vector3 (0,0,4);
// Vector3 c = new Vector3 (1,1,1);
//
// float m  = a.magnitude;
// Vector3 n = a.normalized;
// float A =  Vector3.Angle (a, b);
// Vector3.Cross (a, b);
// Vector3.Project (c, a);
// Vector3 F = Vector3.forward;
// Vector3.Lerp (a, b, 0.1f);
// Vector3.Slerp (a, b, 0.1f);  

// Vector3.MoveTowards (a, b, 0.1f);
// Vector3.SqrMagnitude (a);


// ------------------------
//Random.InitSate(0);




//float AA = Random.value; // 0-1随即数字
//print (System.DateTime.Now.Ticks);//当前时间 -???
//transform.position = Random.insideUnitCircle*5; // 长度1 *5 的圆形,随即再圆形的坐标  在 X Y 平面上, Z是0 的 ;
//transform.position = Random.insideUnitSphere*10 ;// 球体内随机 


//-----------------------------------
//四元素的旋转
//transform.rotation = Quaternion.Euler(new Vector3(0,0,0)); //四元素旋转的 ;
// 欧拉角    Vector3  类型
//transform.eulerAngles = new Vector3(0,0,0);  // 方便人设置的
//Debug.Log (transform.rotation); // 0001 


//Vector3 dir = enemy.position - p.position;
// 望向敌人  /, 一个旋转---- 前方的  
//p.transform.rotation = Quaternion.LookRotation (dir);
print (Application.installMode);

print (Application.isEditor); 
print (Application.isPlaying);
print (Application.companyName);
//当前问件  只读  压缩    PC 路劲   定 
print (Application.dataPath);      //C:/Users/12967/Documents/New Unity Project Aniamtioions/Assets
// 自己建的     读写     PC 路劲   不定
print (Application.persistentDataPath);  //C:/Users/12967/AppData/LocalLow/DefaultCompany/New Unity Project Aniamtioions
// 流, 不压缩,只读      PC 路劲   定 
print (Application.streamingAssetsPath);  //C:/Users/12967/Documents/New Unity Project Aniamtioions/Assets/StreamingAssets
Application.OpenURL ("file:///D:/Unity/一期项目资源/C#课件/第十三讲:委托/_book/chapter3/2.html");
Application.CaptureScreenshot ("截图");
Application.Quit ();    // 编辑不能用
print( Application.isPlaying );  //   
   






}

// Update is called once per frame
void Update () {
//print (Random.Range (4, 10));  // 为随机数--不能取到10 整数
//print (Random.Range (4, 5.5f));  // 小数字


Vector3 dir = enemy.position - p.position;
dir.y = 0;
Quaternion targtrt = Quaternion.LookRotation (dir);
p.rotation = Quaternion.Slerp (p.rotation ,targtrt, Time.deltaTime);


// Vector3 pp = p.position;
// Vector3 pos = Vector3.Lerp (enemy.position, pp, Time.deltaTime);
// p.position = pos;


//p.rotation = Quaternion.Lerp (enemy.position, p.rotation, 0.1f);


if(Input.GetKeyDown(KeyCode.A))
{
UnityEditor.EditorApplication.isPlaying = false; // 退出 模式  
SceneManager.LoadScene("aaa");
SceneManager.LoadScene ("AA", LoadSceneMode.Additive); // 默认是Singe   销毁当前,加载下个,  这个是不销毁的意思;

AsyncOperation OP = SceneManager.LoadSceneAsync ("dd");
  // OP.progress 
}
}
   
}


//=====================================================================
using UnityEngine;
using System.Collections;


public class API02_Time : MonoBehaviour {


public int runCount = 10000;
// Use this for initialization
void Start () {


// 性能测试, 测试方法的运行时间; 执行100万次--- 0.0几秒;贼几把快
float time1 = Time.realtimeSinceStartup ;
for (int i = 0; i < runCount; i++) {
Mth1 ();
}
float time2 = Time.realtimeSinceStartup;
Debug.Log (time2-time1);
for (int i = 0; i < runCount; i++) {
Mth2 ();
}
float time3 = Time.realtimeSinceStartup;
Debug.Log (time3-time2);


}

// Update is called once per frame
void Update () {

//想这个方向移动,且移动这个方向的距离
//transform.Translate (Vector3.forward*100);
// 每帧1米,
// transform.Translate (Vector3.forward);
// 每帧之间的时间间隔  Time.deltaTime    俩次Update 的时间间隔;
// 每帧--运行距离--- Vector3.forward*Time.deltaTime
// 假设这帧是1秒, 1米
// 假设这帧是0.5秒 1此就是半米  
// 假设0.02 也就是50帧 ,  1* 50/1 
// 每帧数移动的距离的和  ---得到一秒内游戏运动的物体 
// 1秒3 ---执行3次Update ---1S距离--0.3Vector3.forward+0.3Vector3.forward+0.3Vector3.forward
// 1秒2帧---1帧时间--距离---1S距离--0.2Vector3.forward+0.2Vector3.forward。。。。
transform.Translate (Vector3.forward*Time.deltaTime);








//游戏运行时间,受暂停影响
   //Debug.Log (Time.time);
//游戏运行时间,受暂停影响
//Debug.Log (Time.fixedTime + "Time.fixedTime");




//每帧之间 游戏影响,
//Debug.Log (Time.deltaTime+"Time.deltaTime");
// Editor progectSeting  -- Time ---FixedTimeStep   0.02 设置  ----1 秒执行50帧数 
// 固定
//Debug.Log (Time.fixedDeltaTime+"fixedDeltaTime");
//是Time.delateTime 的平滑的时间
//Debug.Log (Time.smoothDeltaTime + "smoothDeltaTime");


//游戏开始到现在运行 帧数
//Debug.Log (Time.frameCount + "frameCount");


//游戏运行时间, 游戏暂停,时间还会一直增加
//Debug.Log (Time.realtimeSinceStartup + "realtimeSinceStartup");
//游戏运行时间, 游戏暂停,时间还会一直增加
//Debug.Log (Time.unscaledTime + "Time.unscaledTime ");
// 场景为单位,计算游戏运行时间
//Debug.Log (Time.timeSinceLevelLoad + "timeSinceLevelLoad");




// 0 暂停  time.DlateTime 会  乘以 Time.timeScale    所有使用这个移动的物体会暂停 
// 1 正常 设置时间的比例


//Debug.Log (Time.timeScale + "Time.timeScale ");


}
void Mth1(){
int i = 1 + 2;
}
void Mth2(){
int j = 1 * 2;
}
}
================================================================
using UnityEngine;
using System.Collections;
/// <summary>
///  事件函数
/// 
/// </summary>
public class API01 : MonoBehaviour {
//  
// public Vector3 _Position;
// public Vector3 _Rotation;
// public Vector3 _Scale;
// // Editor 模式能运行,发布后无论啥品台都会,不执行 ---不运行项目时候可以执行,运行后就不执行了
// // 1,点击组件这个组件后,点击右边设置,然后Reset重置数据
// // 2,当被附件,即添加组件后会,执行该方法,  
// // 可以推出---组件的数据重置---写在这里面
// void Reset() 
// {
// Debug.Log ("hahahh");
// _Position = Vector3.zero;
// _Rotation = Vector3.zero;
// _Scale = Vector3.one;
// }


// // 当物体被隐藏---这三个都不执行 Awake()  Start () OnEnable()
// // 1 当场景运行时候
// // 2 物体实例化后调用
// // 3 只一次---脚本激活不激活只要有脚本都会调用
void Awake()
{  
Debug.Log ("Awake");


}
// // 1 只一次,脚本不激活,不会被调用
// // 2, awake 和enable 之后执行
// // Use this for initialization
void Start () {
Debug.Log ("Start");
}
// // 1 启用的时候,物体被激活的时候,
// // 2 多次执行
void OnEnable()
{
Debug.Log (" OnEnable(");
}
//
//
// // Update is called once per frame
// //和游戏设备有关系,如果 运算多了,实际每秒运行了20次,也就是20帧;
// void Update () {
// Debug.Log ("Update");
// }
// // 固定的update 每秒60次和游戏的性能没关系,CF的子弹,
// // 但是FixedUpdate 是固定的60秒;
// void FixedUpdate()
// {
// Debug.Log (" FixedUpdate");
//
// }
// // 在每update 之后的一帧后执行;
// void LateUpdate()
// {
// Debug.Log ("LateUpdate");
//
// }
//    // 取消激活的时候
// 多次执行
void OnDisable()
{
Debug.Log (" OnDisable");
}


// 【渲染的指令】
#region
//-----------------------------------------
// 刚出现在屏幕, 不再输出,出现输出
// void OnWillRenderObject()
// {
// Debug.Log (" OnWillRenderObject");
// Debug.Log ("AHAHAH");
// }
//
// void OnPreCull()
// {
// Debug.Log ("  OnPreCull");
// }
// void OnBecameVisible()
// {
// Debug.Log (" OnBecameVisible");
// }
// void OnBecameInvisible()
// {
// Debug.Log ("OnBecameInvisible");
// }
// void OnPreRender()
// {
// Debug.Log (" OnPreRender");
//
// }
//再场景中,无论看见看不见
// void OnRenderObject()
// {
// Debug.Log (" OnRenderObject");
// }




// void OnPostRender()
// {
// Debug.Log (" OnPostRender()");
// }


//// void OnRenderImage()
//// {
//// Debug.Log (" OnRenderImage"); '
#endregion
//// }
// // 1 编辑模式下使用----绘制物体矩阵的
// 2 gimas --scece 视图中是有这个选项的
void OnDrawGizmos()
{

}
//2ci
// void OnGUI()
// {
//
// }
//  开始一次,??暂停不运行
// void OnApplicationPause()
// {
// Debug.Log (" OnApplicationPause");
// }
// 1  删除物体
// 2  删除该脚本
void OnDestroy()
{
Debug.Log (" OnDestroy()");
}


}








=======================================================================
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System ; // 异常引入空间
public class API03_GameObject : MonoBehaviour {
public GameObject prefab1; 
public GameObject Cube1;
public Sprite sprit2;
public Texture tex;
public Image image;
public RawImage rawImage;
private GameObject cube;
public GameObject target ;
// Use this for initialization
void Start () {
//GameObject 
#region
// 没有物体的
// new Object ();  
// 1 第一种创建方法
//常场景多了一个空物体 ,,卧槽
// new GameObject ();
//空物体,名字叫cube 
// new GameObject ("Cube");
       // 2  
  // 预制体的或场景中的游戏物体去克隆    特效游戏角色等
//new GameObject(prefab);  错
//GameObject.Instantiate(prefab1);
//GameObject.Instantiate (Cube1);


//创建原始的图形  ,给物体添加组建
//GameObject.CreatePrimitive (PrimitiveType.Plane);
//GameObject go=GameObject.CreatePrimitive (PrimitiveType.Sphere);
//go.AddComponent<Rigidbody> ();
//自己定义,也是一样添加
//go.AddComponent<API01> (); 
// 确定游戏物体是否激活
//bool  isActive = go.activeInHierarchy;
//Debug.Log (isActive);
// 不需要渲染,不运行UPdate ,但是还是占用内存的 
//go.SetActive (false);
//Debug.Log (go.activeInHierarchy);


// ------------




// 游戏-场景- 物体(GameObject )--组建(  系统的   自己的脚本 )
// System.Object   UnityEngine.Object 
// 继承关系    GameObject   Component   
// inherited 继承 
// 输出物体的名字 
//Debug.Log(go.name);
//Debug.Log(go.GetComponent<Transform>().name); // 继承来的属性


// 得到的是这个组建的对象--- 销毁这个对象-----组建就被销毁了????????、
//!!!!! 可以认为这个组件 是一个实例化的对象吗????
//Destroy(go.GetComponent<Rigidbody>());
//Destroy(go); //推荐 在场景中不存在,但还是在一个垃圾池子中,
//DestroyImmediate(go); // 不推荐
// 不销毁 
//DontDestroyOnLoad(transform.gameObject);
// 只找到第一个就返回
// 静态方法  ---  类
// 不查找未激活物体的
//Light light  = Object.FindObjectOfType<Light>();
//light.enabled = false ; 
// 不能通过对象调用 gameObject. 出不来
// 相当于在自己的脚本中调用自己的方法 ---继承
//Transform [] trans = FindObjectsOfType<Transform>();
//foreach (var item in trans) {
//Debug.Log(item.name);
//}
//------------------------------------------
// sprite HE texture 区别
// 图片放入场景中---就是gameObject  ---- 场景中的物体都是GameObject ---再拖入文件就是预制体了
// 1 sprit 一般做UI的可以←图集--优化DrawCall ,但Texture 也行,Texture 做大的背景 一个DrawCall, 但是2的N次方再Andriod 和IOS 品上占资源很小 
// 2 sprit 可以做动画,但是Texture 是不行的
// 3 sprit Render 组件可以让物体 sptite 直接拖入场景中  ,Texture 不能 拖入场景
// 4 大的纹理底纹就使用Textture ,一般模型贴图,Sprit UI 的
// Sprite go1 =  Instantiate<Sprite>(sprit2);
// go1.name = "sprite";
// image.sprite = go1;
// 报个小错误
// Texture t = Instantiate<Texture>(tex);
// t.name = "texture";
// rawImage.texture = t;
//-------------------------------------
// 不能找影藏,
//      // try catch 
// try{
// cube = GameObject.Find("Cube");
// cube.SetActive(false);
// }
// //小异常
// catch( NullReferenceException  excepiton )
// {
// Debug.Log("没有啊");
// // 返回第一个
//
// }
//所有异常
// catch( Exception  ex)
// {
// Debug.Log("all 异常");
// }
//都执行
// finally
// {
// Debug.Log("找倒找不到执行---");
// }
//tag 
// GameObject camera = GameObject.FindGameObjectWithTag("MainCamera");
// camera.SetActive(false);
// //数组
//GameObject[] c = GameObject.FindGameObjectsWithTag("MainCamera");
//GameObject cam = GameObject.FindWithTag("MainCamera");
///-----------------------------------------------------------
/// 
///对象方法
//1 组件类
// 得到自身的一个组件,多个只找第一个
 Transform trans = GetComponent<Transform> ();
// 多个组件
 Transform [] transs =  GetComponents<Transform>();
//孩子和自己的组件 --同类型的
     Transform [] t =  GetComponentsInChildren<Transform>();
// 父亲物体的组件和自己的组件---同类型的
 Transform [] t2 = GetComponentsInParent<Transform>();


//2 Message 类
// 1  自身+子物体  广播方法, 不需要接收谁接收 只要 自己和孩子有这个方法名字都被调用   ----拿到组件的引用也能发消息,可以减少耦合性,高了不好
//    SendMessageOptions.DontRequireReceiver-- 不一定需要,由就传每酒算了,  还有一个必须由接收者
// target.BroadcastMessage("Attack","Hellow",SendMessageOptions.RequireReceiver);
// 2  对一个物体上所有脚本中有这个名字的方法,,发送消息; 只自己
// target.SendMessage("Attack","Hellow",SendMessageOptions.RequireReceiver);
// 3  向上发送消息,每级数是只能有一个父亲物体的 
// target.SendMessageUpwards("Attack","hehe",SendMessageOptions.DontRequireReceiver);




#endregion
  
}

// Update is called once per frame
void Update () {

}
}
=================================================
//using UnityEngine;
//using System.Collections; 
//// 不点开始再编辑模式下会运行  
// //[ExecuteInEditMode]   
///// <summary>
/////   MOnobehiever 
/////   多个组件,拖拽,创建多个inspector 面板
///// </summary>
//public class API04_Monobehiever : MonoBehaviour {
//
// public GameObject cube;
// // Use this for initialization
// void Start () {
// //基本属性
// #region
//// Debug.Log (this.isActiveAndEnabled);  // true 这个脚本 自身是否被激活 
//// Debug.Log (this.enabled);    // true 自身是否被激活 
//// enabled = false;     
//// //禁用自己都能使用?????? 
//// //但是Update 不能用了,会把start 方法执行完
//// Debug.Log (name);      // light 
//// Debug.Log (tag);       //untagged 
//// Debug.Log (gameObject); 
//// Debug.Log (transform);
////
//// Debug.Log (@" /\
////             /  \
////                    /    \
////                   /      \ 
////                  /_ _ _ _ \         ");
// #endregion
// //Invoke
//
// //  5秒后调用一次啊 , 
// //  调用可以由返回值但是不能由参数----所以才会由协成啊
// //Invoke ("GetName",5f);
// //Invoke ("Add",10f); // 没有
// //InvokeRepeating("GetAge",3,0.5f);
// //----------------------------------
// //Coroutines
// //IEnumerator
//
//
// }
// private IEnumerator ie;
// // 脚本没由Update方法就没有禁用的选项
// // Update is called once per frame
// void Update () {
//
//    //---改变场景输出
// // Debug.Log ("不点开始再编辑模式下会运行");
// //不继承MOno 是不能使用额啊
// //print ("Monebehiever的静态方法");
//
// //--------------------------
// //添加倒掉用队列中,调用完后会为false;没掉用时True 
// //bool res =IsInvoking("GetName");
// //Debug.Log (res);
//    //开启协成---1 方法名子
// //         2 方法调用
//
// StartCoroutine(Add(12,23,12)); //47
//
// if (Input.GetKeyDown (KeyCode.A))
// {   //fuzhi
// ie = ChangeColor ();
//
// StartCoroutine (ie);
// //通过名字只能传递一个参数
// StartCoroutine ("ChangeColor");
// }
// //停止协成
// if (Input.GetKeyDown (KeyCode.S))
// {
// StopCoroutine(ie);
// StopCoroutine("ChangeColor");
//
// }
// }
//
// public int GetName()
// {
// Debug.Log ("GetName()。被5秒后调用");
// return 5;
// }
//
// public int Add (int x , int y ){
//   
// int z = x + y;
//    return   z ;
// }
//
// public int GetAge()
// {
// Debug.Log ("GetAge(),1秒几次");
// return 1;
// }
// //--------------------------------------------------
// // 方法迪调用----顺序执行,先指执行完方法再执行下一个;
// // 协成方法 -- 不会再等协程执方法行完,就继续向下执行--执行下面的方法;
// // 返回值是---是IEnmerator  不能由返回值???卧槽
// IEnumerator Add (int x ,int y,int z ){
// int m = x + y+z;
// print ("11");  
// yield return new WaitForSeconds (2f);
//
// Debug.Log (m);
// }
//
// IEnumerator ChangeColor()
// {
//   // 白倒黑
// for (float i = 0; i < 1; i += 0.1f) 
// {
////    cube.GetComponent<MeshRenderer> ().material.color = new Color (i,i,i,i);
//// // 必须由这个返回值 
//// // 每次都会等一秒,所以会有是//10个阶段;
//// yield return null;
//// yield return new WaitForSeconds (1f);
//      ///--------------------------------------------
//
//
// }
// //死循环
// for(;;)
// {    
// //color 值类型的啊
// Color color = cube.GetComponent<MeshRenderer> ().material.color;
// cube.GetComponent<MeshRenderer> ().material.color = Color.Lerp (color, Color.red, 0.02f);
// //cube.GetComponent<MeshRenderer> ().material.color= color_;
// yield return new WaitForSeconds (0.1f);
//
// if (Mathf.Abs(Color.red.g - color.g)<=0.1f) 
// {
// break;
// }
// }
//
// }
// /// </summary>----
// /// 有碰撞器,射线识别的
// /// 没有是触发器,找倒物理射线点击的
// void OnMouseEnter(){
// Debug.Log ("OnMouseEnter()");
// }
// void OnMouseExit(){
// Debug.Log ("OnMouseExit");
// }
//
// void OnMouseOver(){
// Debug.Log ("o");
// }
//
// void OnMouseDown(){
// Debug.Log ("d");
// }
// void OnMouseUp(){
// Debug.Log ("u");
// }
//
// void OnMouseDrag(){
// Debug.Log ("ddd");
// }
// //按下了,但是有不想触发了----手移走了。。。没执行
// void OnMouseUpAsButton()
// {
// Debug.Log ("OnMouseUpAsButton()");
// }
//
//}
==========================================================
using UnityEngine;
using System ;
using System.Collections;
using UnityEngine.UI;
public class API05_delgateTest : MonoBehaviour {
private int cc = 0;
public  Text t;
// 自己又定义了一个,没干系的事件;
// event  不能用对象调用
// 委托定义再里面。 类字段定义使方法方法对象
public event API05_Mathf.IndexDelegate a;
    //委托定义再外面 ,直接定义事件对象
//public event IndexDelegate  a;


private API05_Mathf API05_M;
 
// Use this for initialization
void Start () {
t.text = 1.ToString ();
a += Aa;
// 单例子模式
API05_Mathf._instance.indexEvent += BB;
//


}

// Update is called once per frame
void Update () {

}


//
public void Aa(int a ){
cc = a;
t.text = Convert.ToString (cc);
}


//  a 是指传入的值。传入的数值范围,会变化比比较后的范围大1 ;
public void BB(int a ){
cc =a ;
t.text = Convert.ToString (cc);
}


public void BtnCClick(){


a (50);
// API05_Mathf._instance.indexEvent (500);
// 错的啊。事件不但能对像调用。
}


}
========================================================
using UnityEngine;
using System.Collections;
using UnityEngine.UI;


//public delegate void IndexDelegate( int a)  ; // 对的
//public event  IndexDelegate indexEvent; 错
public class API05_Mathf : MonoBehaviour {
public delegate void IndexDelegate( int a) ;
public static API05_Mathf _instance;
//public delegate void IndexDelegate( int a)  ;
public event  IndexDelegate indexEvent;
// 结构体,Mathf 静态工具类 -----不用实例化去平凡调用方法
// Use this for initialization


public Text _text;


private int _index;


public  GameObject cube;
void Awake(){
_instance = this; 
}
public int Index
{
set{

indexEvent (value);


}
get{
return _index;
}
}


public void OnIndexChanged( int a )
{  
//_index = Mathf.Clamp (a, 1, 5);


//----传入的值
if (a <=1) {
a= 1;
} else if (a >=5) {
a = 5; 

_index = a;
_text.text = _index.ToString ();


}


public void Onleftdown(){

Index--;
}
public void Onrightdown(){
Index++;
}


void Start () {


indexEvent += OnIndexChanged ;
_text.text= 1.ToString ();
//Mathf
#region
//
// // 静态字段
//
// //度数变弧度  乘以即可   是一个数值 0.017
// print (Mathf.Deg2Rad);
// //弧度变度数,乘以即可  是一个数值 380/PI*2  = 57
// print (Mathf.Rad2Deg);
// //表示一个无穷小的数

//
// print (Mathf.Epsilon);
// //无线大的数字
// print (Mathf.Infinity);
// //无线小的数字
//
// print (Mathf.NegativeInfinity);
// print (Mathf.Ceil(10.2f));
// print (Mathf.CeilToInt(10.2f));
// print (Mathf.Floor(-10.2f)); // -11
// print(Mathf.FloorToInt(10.2F));
// print (Mathf.Round(10.2f));
// //限制一个数字,再这个范围;
// // hp = Mathf.Clap(0.100);
// float a = Mathf.Clamp(Time.time,1,10);
// Debug.Log (a);
// // 最小角度
// Debug.Log (Mathf.DeltaAngle (370,10));
// Debug.Log (Mathf.Max (12,13));
// Debug.Log (Mathf.Pow(2,3));  //2 的3 次方  
// Debug.Log(Mathf.Sqrt(2));  //2的平法根
// Debug.Log(Mathf.ClosestPowerOfTwo(20));//16 和2的平方最接近的数字
#endregion
}

// Update is called once per frame
void Update () {
 
float x = cube.transform.position.x;
//float newx = Mathf.Lerp (x, 10, 0.1f);
//差值
//float newx = Mathf.Lerp (x, 10,Time.deltaTime);
//匀速 ,没次0.02 米50帧1米, 10 米--    当前值 + 后面值,但是不会超过
float newx =  Mathf.MoveTowards(x,10,0.02f);
//cube.transform.position.x = newx;  错, 不能没帧修改 
float newxx = Mathf.LerpAngle(10,350,0.1f);  //    8     350     10  
//t = 0 ,t 是速度,再0-10 变化
float tf = 0;
float newxxx = Mathf.PingPong(tf,10);
//cube.transform.position = new Vector3 (newx, 0, 0);
// 来回运动 
cube.transform.position = new Vector3 (Mathf.PingPong(Time.time,10), 0, 0);


Debug.Log (newxx);
}

}
========================================================================
using UnityEngine;
using System.Collections;


public class API06_Input : MonoBehaviour {


// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.A)) {
//按下的一帧执行
Debug.Log("GetKeyDown");
}
if (Input.GetKeyUp(KeyCode.A)) {
//松开的一帧执行
Debug.Log("GetKeyUp");
}
if (Input.GetKey(KeyCode.A)) {
//按下后----一值执行 ---抬起来不执行
Debug.Log("GetKey(KeyCode.A)");
}
if (Input.GetMouseButton(0)) {
//按下后----一值执行 ---抬起来不执行
Debug.Log("GetMouseButton(0)");
}
if (Input.GetMouseButtonDown(1)) {
//按下后----一值执行 ---抬起来不执行
Debug.Log("GetMouseButtonDown(1");
}
if (Input.GetMouseButtonUp(2)) {
//按下后----一值执行 ---抬起来不执行
Debug.Log("GetMouseButtonUp(2");
}
//多个按键,触发同一个,事件,
//形象,好懂
if (Input.GetButtonDown ("Fire1")) 
{
Debug.Log ("Fire1");
}
if (Input.GetButtonUp ("Fire1")) 
{
Debug.Log ("Fire222");
}
if (Input.GetButton("Fire1")) 
{
Debug.Log ("Fire133333");
}
Debug.Log(Input.GetAxis("Horizontal"));






}
}
================================
using UnityEngine;
using System.Collections;


public class LOAD : MonoBehaviour {


private GameObject go;
private GameObject a;
// Use this for initialization
void Start () {
   
a = (GameObject)Resources.Load ("GameObject");
go = Instantiate (a);
     //go.SetActive (true);

}

// Update is called once per frame
void Update () {
// go = Instantiate (a);
}
}
============================================
using UnityEngine;
using System.Collections;


public class Target : MonoBehaviour {


public string namee;
public string aaa;
public Target (string namee)
{

}
// Use this for initialization
void Start () {

}

// Update is called once per frame
void Update () {

}
void Attack (string a )
{  


Target t = new Target (a){ };

Debug.Log (t.namee);


Debug.Log (aaa+a);
}
}















































猜你喜欢

转载自blog.csdn.net/july_unity/article/details/79266423
今日推荐