移動網(wǎng)站性能網(wǎng)絡(luò)廣告營銷的特點
準(zhǔn)備
- 創(chuàng)建Scenes場景,Scripts腳本,Prefabs預(yù)制體文件夾
修改背景顏色
-
選中Main Camera
-
找到背景
-
選擇顏色,一種白中透黃的顏色
創(chuàng)建小球
-
將文件夾里的Circle拖入層級里
-
選中Circle,位置為左右居中,偏上,顏色為黑色,大小縮為0.7
分數(shù)
-
創(chuàng)建Text
-
刪除掉EventSystem,因為本例中UI不需要做任何事件
-
選中Text,點擊重置,文本居中,顏色為白色,內(nèi)容為0
- 選中Canvas,將渲染模式改為世界空間,接著修改大小,改為100.100
-
將縮放改為0.01,拖動到小球上
-
使得Circle和Canvas的位置坐標(biāo)一致,都為0,2,0
-
選擇MainCamera設(shè)置為Canvas的事件攝像機
小球運動
-
創(chuàng)建一個腳本,選擇MonoBehaviour,命名為RotateSelf
-
將此腳本掛載到Circle的下面
-
編寫腳本
using JetBrains.Annotations;
using UnityEngine;public class RotateSelf : MonoBehaviour
{public float speed = 90;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){}// Update is called once per framevoid Update(){transform.Rotate(new Vector3(0, 0, speed * Time.deltaTime));}
}
- 在場景中點擊播放,可以看到Circle在逆時針旋轉(zhuǎn),如果想要順時針旋轉(zhuǎn),在speed前加一個負號
針頭
- 將針導(dǎo)入到層級里,將Pin的大小適當(dāng)放大
-
制作針的尾部,復(fù)制一個Circle
-
調(diào)整大小位置顏色
-
將Pin拖入Prefabs文件夾里,方便進行實例化創(chuàng)建
-
給針頭添加碰撞器,選中針頭,在檢查器底下的添加組件,搜Circle Collider 2D添加
生成針
-
創(chuàng)建兩個空對象,將第一個命名為StartPosition
-
將Pin放到StartPosition的下面,這樣可以進行預(yù)覽,調(diào)整位置
- 將StartPosition復(fù)制,拖到屏幕外面進行實例化
-
然后刪去針,改名為SpawnPositon
-
創(chuàng)建一個空對象,命名為GameManager
-
創(chuàng)建一個GameManager腳本,掛載到對象下面
using UnityEngine;public class GameManager : MonoBehaviour
{private Transform startPosition;private Transform spawnPosition;public GameObject pinPrefab;// Start is called once before the first execution of Update after the MonoBehaviour is createdvoid Start(){startPosition = GameObject.Find("StartPosition").transform;spawnPosition = GameObject.Find("SpawnPosition").transform;SpawnPin();}// Update is called once per framevoid Update(){}void SpawnPin(){GameObject.Instantiate(pinPrefab, spawnPosition.position, pinPrefab.transform.rotation);}
}
-
將PIn實例拖到右邊的Pin Prefab里
-
點擊運行后屏幕外生成了針