unity常用脚本
来源:互联网 发布:s团淘宝兼职是真的吗 编辑:程序博客网 时间:2024/06/05 12:05
位移:
transform.Translate (Vector3.forward*Time.deltaTime*100f);
transform.position+=transform.forward*Time.deltaTime*100f;
注意区分上面两句话,第一句话的移动是相对于自身的移动
第二句移动是全局位置
在第一句话和第二句话实现的效果一样
public int type;
private float passDis=0;
private float passTime=Time.time;
void FixedUpdate () {
transform.position += currentPlayer.transform.forward * Time.deltaTime * currentPlayer.GetSpeed ();
//子弹的位置是朝子弹前方移动 移动的过程中受重力影响
if (type == 2) {//说明是三发制子弹的其中一颗,需要重力
transform.position+=transform.forward*Time.deltaTime*80f;
float temp = 5 * (Time.time - passTime) * (Time.time - passTime) * 1f;
transform.position -= new Vector3 (0, temp - passDis, 0);
passDis = temp;// g * t^2 /2
// Debug.Log("这一帧下降的距离 以及实际走过的距离:"+ (temp - passDis) + " "+temp);
//模拟导弹追踪
transform.position=Vector3.MoveTowards(transform.position,targetPlayer.transform.position+new Vector3(0,2,0),Time.deltaTime*50);//80
transform.up = targetPlayer.transform.position - this.transform.position;//朝向
//播放粒子特效
#region 播放特效重载 该特效现在用于播放保护技能的特效,别的暂时不要用该方法
public static void PlayFxAt( Transform posTrans, Vector3 offset, string name,float time,bool isParent=false)//不要目标 int targetPlayerID,目标是攻击的时候点到谁算谁
{
GameObject fxPrefab = MonoBehaviour.Instantiate ( (GameObject)Resources.Load ("Partical/" + name), posTrans.position+offset, Quaternion.identity) as GameObject;
if (isParent)
fxPrefab.transform.parent = posTrans;
else
Debug.Log ("不跟随的特效");
ParticleSystem fx1 = fxPrefab.GetComponent<ParticleSystem>();
fx1.Play ();
// fx.transform.position = player.transform.position;//位置赋值
// ParticleSystem fx1 = fx.GetComponent<ParticleSystem>();
// fx1.Play();
Debug.Log ("按照指定位置播放粒子:"+fxPrefab.name);
GameObject.Destroy(fxPrefab.gameObject,time);
// GameObject objPrefab = MonoBehaviour.Instantiate ((GameObject)Resources.Load ("bullet"), Vector3.zero, Quaternion.identity) as GameObject;
// gameObject.GetCompoment<ParticleSystem>().Play();
//找到
}
#endregion
/// <summary>
/// 更换材质
/// </summary>
/// <param name="name">贴图名称</param>
public void ChangeMaterial1(string name)
{
mt=Resources.Load("Materials/"+name) as Material ;//加载出来作为对象
//Renderer[] skinMR = this.GetComponentsInChildren<Renderer>();
Renderer[] skinMR = this.GetComponentsInChildren<SkinnedMeshRenderer>();
foreach (var p in skinMR) {
Debug.Log ("这一个的: tag: "+p.gameObject.tag+ " "+p.gameObject.name);
if (p.gameObject.tag == "Model") {
p.sharedMaterial = mt;
return;
}
//skinMR [1].sharedMaterial = mt;
}
}
#region 发射三发装 以及动画
public void BulletShoot1(int playerID, int targetID ,float angle=15f )//第三个参数暂时不用
{
// Debug.Log ("同步一枚子弹playerID to targetID" + playerID +" "+targetID);
Debug.Log ("发射三发制子弹");
if (playerID == KPlayer.I.playerInfo.id) {
Debug.Log ("");
}
KPlayer player = KPlayerManager.I.FindPlayer (playerID);
// GameObject bu=(GameObject)Resources.Load("Item/bullet");
for (int i = 0; i < 3; i++) {
bullet[i]=MonoBehaviour.Instantiate((GameObject)Resources.Load("Item/bullet1"),Vector3.zero,Quaternion.identity) as GameObject;
GameObject.Destroy (bullet[i], 5f);
bullet[i].GetComponent<bullet_trigger> ().currentPlayer = player;
bullet[i].transform.position = player.trans.position+new Vector3( 0,3f,0);
}
KPlayer target = KPlayerManager.I.FindPlayer( targetID ); //player.targetPlayerID
if (target) {
Vector3 y = target.trans.position - player.trans.position;
bullet[1].transform.localRotation = Quaternion.LookRotation (y);
bullet[1].transform.rotation = Quaternion.Euler (bullet[1].transform.eulerAngles );
bullet[0].transform.rotation = Quaternion.Euler (bullet[1].transform.eulerAngles + new Vector3 (0, -10, 0));
bullet[2].transform.rotation = Quaternion.Euler (bullet[1].transform.eulerAngles + new Vector3 (0, 10, 0));
} else {
bullet[0].transform.rotation = Quaternion.Euler (bullet[1].transform.eulerAngles + new Vector3 (0, -10, 0));
bullet[2].transform.rotation = Quaternion.Euler (bullet[1].transform.eulerAngles + new Vector3 (0, 10, 0));
Debug.Log ("发射的子弹没有朝向啊 -----------------targetid:"+targetID);
}
}
#endregion
这句话
transform.rotation = Quaternion.Euler(transform.eulerAngles + (new Vector3(x,y,z));
如何修改gui的参数
void OnGUI()
{
string aa = "我们都很好";
GUIStyle bb=new GUIStyle();
bb.normal.background = null; //这是设置背景填充的
bb.normal.textColor=new Color(1,0,0); //设置字体颜色的
bb.fontSize = 40; //当然,这是字体颜色
GUI.Label(new Rect(0, 0, 200, 200), aa,bb);
}
- Unity常用脚本函数
- unity常用脚本
- Unity常用脚本API
- Unity 3d 常用脚本
- Unity脚本生命周期常用方法
- Unity常用脚本类的继承关系
- Unity常用脚本类的继承关系
- Unity常用脚本类继承关系图
- Unity常用脚本函数随用随记
- Unity 基础常用的脚本(一)
- Unity脚本
- unity 脚本
- Unity-脚本
- [Unity]界面GUI程序常用的脚本类
- unity学习之Unity3D 脚本常用方法快速参考
- 【Unity】常用脚本类的继承关系(入门篇)
- 2.《Unity中C#脚本语法-常用变量类型》
- Unity常用类之脚本、对象与组件
- (4.3.2.19)activity 设置Theme.Dialog View高度
- 使用STM32CubeMx创建U盘读写程序
- jsp中文乱码分类及其处理方法
- curl 使用 ~/.netrc ( Windows 上是 _netrc ) 问题
- 在 Linux 上配置一个 syslog 服务器
- unity常用脚本
- spring data jpa多表查询
- Redis的资料汇总--不错的redis资料
- C#网页cookie中文乱码问题解决方法
- 使用sklearn与pybrain预测搜索相关性实战
- 网络图片查看器
- MySQL5.7的密码破解
- SDL库的学习笔记之一—devcpp环境配置
- checkbox js----复选框