资源简介
研究生课程作业,Unity做的贪吃蛇小游戏,简单好学,希望Unity新手能跟我一起学习交流。
代码片段和文件信息
using UnityEngine;
using UnityEngine.UI;
public class FoodMaker : MonoBehaviour
{
private static FoodMaker _instance;
public static FoodMaker Instance
{
get
{
return _instance;
}
}
public int xlimit = 21;
public int ylimit = 13;
public int xoffset = 7;
public int yoffset = 2;
public Gameobject foodprefab;
public Gameobject rewardPrefab;
public Sprite[] foodSprites;
private Transform foodHolder;
void Awake()
{
_instance = this;
}
void Start ()
{
foodHolder = Gameobject.Find(“FoodHolder“).transform;
MakeFood(false);
}
public void MakeFood (bool isReward)
{
//随机出现食物和随机位置出现
int index = Random.Range(0 foodSprites.Length);
Gameobject food = Instantiate(foodprefab);
food.GetComponent().sprite = foodSprites[index];
food.transform.SetParent(foodHolderfalse);
int x = Random.Range(-xlimit + xoffsetxlimit);
int y = Random.Range(-ylimit + yoffset ylimit);
food.transform.localPosition = new Vector3(x * 30y * 30 0);
if (isReward)
{
Gameobject reward = Instantiate(rewardPrefab);
reward.transform.SetParent(foodHolder false);
x = Random.Range(-xlimit + xoffset xlimit);
y = Random.Range(-ylimit + yoffset ylimit);
reward.transform.localPosition = new Vector3(x * 30 y * 30 0);
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 1499728 2018-04-28 15:55 Unity贪吃蛇游戏\104753170667朱东伟.docx
..A..H. 115200 2018-04-28 15:56 Unity贪吃蛇游戏\HappySnake\.vs\HappySnake\v15\.suo
文件 0 2018-04-26 10:29 Unity贪吃蛇游戏\HappySnake\.vs\HappySnake\v15\Server\sqlite3\db.lock
文件 675840 2018-04-28 15:56 Unity贪吃蛇游戏\HappySnake\.vs\HappySnake\v15\Server\sqlite3\storage.ide
文件 795564 2017-09-19 19:58 Unity贪吃蛇游戏\HappySnake\Assets\Audio\BGM.mp3
..A..H. 462 2017-09-19 20:16 Unity贪吃蛇游戏\HappySnake\Assets\Audio\BGM.mp3.me
文件 22050 2017-09-19 19:58 Unity贪吃蛇游戏\HappySnake\Assets\Audio\Die.mp3
..A..H. 462 2017-09-19 20:16 Unity贪吃蛇游戏\HappySnake\Assets\Audio\Die.mp3.me
文件 11086 2017-09-19 20:11 Unity贪吃蛇游戏\HappySnake\Assets\Audio\Eat.mp3
..A..H. 462 2017-09-19 20:16 Unity贪吃蛇游戏\HappySnake\Assets\Audio\Eat.mp3.me
..A..H. 191 2017-09-19 20:15 Unity贪吃蛇游戏\HappySnake\Assets\Audio.me
文件 80375 2018-04-24 21:02 Unity贪吃蛇游戏\HappySnake\Assets\Effects\ExpFbx.prefab
..A..H. 209 2017-09-19 20:43 Unity贪吃蛇游戏\HappySnake\Assets\Effects\ExpFbx.prefab.me
文件 2064 2018-04-24 21:02 Unity贪吃蛇游戏\HappySnake\Assets\Effects\ExpMat.mat
..A..H. 207 2017-09-19 20:28 Unity贪吃蛇游戏\HappySnake\Assets\Effects\ExpMat.mat.me
..A..H. 191 2017-09-19 20:46 Unity贪吃蛇游戏\HappySnake\Assets\Effects.me
文件 2984936 2011-12-30 18:16 Unity贪吃蛇游戏\HappySnake\Assets\Fonts\Makefont_Yueyuan.otf
..A..H. 488 2017-09-19 20:16 Unity贪吃蛇游戏\HappySnake\Assets\Fonts\Makefont_Yueyuan.otf.me
..A..H. 191 2017-09-19 20:15 Unity贪吃蛇游戏\HappySnake\Assets\Fonts.me
文件 2971 2018-04-26 21:41 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\Food.prefab
..A..H. 232 2018-04-26 16:00 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\Food.prefab.me
文件 3031 2018-04-27 18:36 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\Reward.prefab
..A..H. 232 2018-04-27 11:27 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\Reward.prefab.me
文件 2976 2018-04-28 09:10 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\SnakeBody.prefab
..A..H. 232 2018-04-26 17:05 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\SnakeBody.prefab.me
文件 4422 2018-04-28 09:10 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\SnakeHead.prefab
..A..H. 232 2018-04-26 14:55 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs\SnakeHead.prefab.me
..A..H. 214 2018-04-26 14:54 Unity贪吃蛇游戏\HappySnake\Assets\Prefabs.me
文件 5033 2017-09-19 19:14 Unity贪吃蛇游戏\HappySnake\Assets\Resources\sb0101.png
..A..H. 2068 2017-09-20 11:57 Unity贪吃蛇游戏\HappySnake\Assets\Resources\sb0101.png.me
............此处省略767个文件信息
评论
共有 条评论