2月28日
学了两个礼拜的unity,到今天才想起来得整个东西记录一下学习和问题啥的,失策了。
亡羊补牢从今天开始也不算晚。
就记录一下还记得的一些问题吧。
下面是关于脚本script的一些内容
GameObject:十分重要,场景内的组件都可用这个来定义
Vector2<x,y>:2d坐标
随机取得位置函数:
private Vector2 RandomPosition()
{
//随机取得位置
int PositionIndex = Random.Range(0, positionList.Count);
Vector2 pos = positionList[PositionIndex];
positionList.RemoveAt(PositionIndex);
return pos;
}
将创建出来的场景物体都归到一个文件夹中:
GameObject go = GameObject.Instantiate(WallPrefab, pos, Quaternion.identity);
go.transform.SetParent(MapHolder);
主角的碰撞检测:
//碰撞检测
collider.enabled = false;//去掉自身所处位置的碰撞
RaycastHit2D hit = Physics2D.Linecast(TargetPos,TargetPos+new Vector2(h,v));//(开始位置,结束位置)
collider.enabled