unity3d三款游戏完整(入门进阶必备)代码.pdfVIP

  • 1
  • 0
  • 约2.76万字
  • 约 30页
  • 2023-03-26 发布于天津
  • 举报

unity3d三款游戏完整(入门进阶必备)代码.pdf

一.太空陨石大战 //******控制太空背景向下移动的游戏脚本****** using UnityEngine; using System.Collections; public class BackgroundContoller : MonoBehaviour { public float speed=1.0f;//设置背景向下移动的速度 // Use this for initialization void Start () {}// Update is called once per frame void Update () { transform.Translate(0,-speed*Time.deltaTime,0);//实现背景向下移动 if(transform.position.y-5.17f) //判断背景是否移出主摄像机照射区域(即游 戏屏幕)transform.position=new Vector3(0,12,1); //若移出,则重新设置游戏背景 Y 轴位置如0,6,12 ,// 以便实现无缝连接使游戏背景连续播放}} using UnityEngine; using System.Collections; public class ExplosionController : MonoBehaviour { public int index=0; public int frameNumber=7;//定义帧数,爆炸动画由7 帧组成 float frameRate=0;//定义帧速率 float myTime=0; 1 / 30 int myIndex=0; // Use this for initialization void Start () { frameRate=1.0f/frameNumber;// 帧速率,帧数framenumber=7} // Update is called once per frame void Update () { myTime+=Time.deltaTime; //统计爆炸效果动画累计播放的时间 myIndex=(int)(myTime*frameNumber); //计算“我的索引值” ,使用(int )转成整形:0,2,3,4,5,6 //Debug.Log((int)(myTime*frameNumber)); //Debug.Log((int)(myTime*frameNumber)); index=myIndex % frameNumber ; // 除以7 求余数得索引:0,2,3,4,5,6 //Debug.Log(myIndex % frameNumber); render.material.mainTextureScale=new Vector2(frameRate,1); //通过render.material.mainTextureScale 设置tiling 帧宽属性 render.material.mainTextureOffset=new Vector2(index*frameRate,0); //通过render.material.mainTextureOffset 设置帧偏移量 if(index==frameNumber-1)//如果动画帧数播放完等于6,即索引等于6,则 销毁动画 2 / 30 Destroy (gameObject);}} using UnityEngine; using System.Collections; public class LoseController : MonoBehaviour { public Texture loseTexture; // Use this for initialization

文档评论(0)

1亿VIP精品文档

相关文档