【SIKIA计划】_06_Unity2D游戏开发-拾荒者笔记

【新增分类】

Animations 动画

——Animation

——AnimatorController

Prefabs 预制

 

【素材导入】

unitypackage 素材包

Sprites Editor 编辑图片(切图之类)

 

【素材应用】

1.选取一个动作多张图片拖动到Hierarchy生成动画

2.带有Sprite Renderer和Animator组件

3.在project会生成anim(动画)和controller(控制)文件

4.选取另一个动作多张图片拖拽到刚生成的物体则不会创建新物体

5.把物体拖拽到project生成预制体

 

(同一控制不同动画处理)

6.右键创建Animator Overide Controller重写一个相同的控制器,指定重写对象

7.把2动画借1物体生成动画,并改1物体指定控制和重写的状态机指定动画。

 

 

【动画编辑】【动画状态机】

Animator 动画编辑器 状态机

idle 待命

attack 攻击

damger 受伤

 

Trigger

——Has Exit Time 前一个动画播放完触发

——Exit Time 多久进行切换

——Transition Duration 转化时间(3D需要融合时间)

 

[动画组件]

private Animator animator;

 

animator = GetComponent<Animator>();

 

animator.SetTrigger("Attack");

 

 

【固定生成】【设置父类】

//创建一个空物体,创建脚本

GameObject[] outWallArray;

//指定预设物体

private Transform mapHolder;(1)

//地址

public int rows=10;

public int cols=10;

 

private void InitMap(){

//初始化地图,

mapHolder = new GameObject("Map").transform;(2)

for(int x=0;x<cols;x++){

for(int y =0; y <rows;y++){

if(x==0||y==0||x==cols-1||y==rows-1){

int index = Random.Range(0,outWallArray,length)

GameObject go = GameObject.Instantiate(outWallArray[index],new vector3(x,y,0),Quaternion.identity)as GameObject;

//对象,位置,旋转

go.transform.SetParent(mapHolder):(3)

//设置父类

}

}

}

}

 

【随机生成】【List的使用】

public GameObject[] wallArray;

public int minCountWall = 2;

public int maiCountWall = 8;

private List<Vector2> polistionList = new List<Vector2>();

positionList.Clear();

for(int x = 2; x < cols-2;x++){

for(int y = 2; y < cols-2;y++){

positionList.Add(new Vector2(x,y))

}

}

//障碍物的地址

int wallCount = Random.Range(minCountWall, maxCountWall + 1);、

//障碍物的个数

for(int i = 0;i <wallCount;i++){

int positionIndex = Random.Rabge(0,positionList.Count)

Vector2 pos = positionList[positionIndex];

positionList.Remove(positionIndex);

//随机取得位置,移出列表

int wallIndex = Random.Range(0,wallArray.length);

//随机取得障碍物

GameObject go = GameObject.Instantiate(wallArray[wallIndex],pos,Quaternion.identity) as GameObject ;

go.transform.SetParent(mapHolder):

}

注意:记得设置墙体和障碍物层数

 

【互相调用】

同一物体两个组件

{GameManager}

public int level

{MapManager}

private GameManager gameManager;

gameManager = this.GetComponent<GameManager>();

 

不同物体两个组件

{GameManager}

public List<Enemy> enemyList = new List<Enemy>();

{Enemy}

GameManager.Instance.enemyList.Add(this);

 

【预设输入】

float h = Input.GetAxisRaw("Horizontal");

float h = Input.GetAxisRaw("Vertical");

if(h>0){

v = 0;

}

 

【刚体组件】

rigidbody.MovePosition(Vector2.Lerp(transform.position,targetPos.smoothing*Time.deltaTime));

//差值(初始位置,目标位置,速度)

 

【计时休息】

public float restTimer = 1;//限时多少

private float restTime = 0;//计时器

restTimer += Time.deltaTime;

if(restTimer<restTime)retrun;

//运行

restTimer = 0;

 

【目标检测】

colider.enabled = false; //自身collider禁用

RaycastHit2D hit = Physics2D.Linecast(targetPos,targetPos + new Vector2(h,v));

//初始位置,目标位置

collider.enabled = true;

if(hit.transform == null){

targetPos += new Vector2(h,v);

}else{

switch(hit.collider.tag) {

case"OutWall"

break;

case"Wall"

hit.collider.SendMessage("TakeDamage")

}

}

restTimer = 0;

//碰撞到物体标签

 

【物体查找】

private Transform player

player = GameObject.FindGameObjectWithTag("player").transform;

 

【AI判断】

Vector2 offset = player.position - transform.position;

if(offset.magnitude<1.1f){

//攻击

}else{

float x = 0, y = 0;

if(Mathf.Abs(offset.y)>Mathf.Abs(offset.x)){

//按照Y轴移动,绝对值

if(offset.y<0){

y = -1;

}else

{

y = 1;

}

}else{

//按照x轴移动

if(offset.x > 0){

x = 1;

}else{

x = -1;

}

}

tagetPosition +=new Vector2(x,y);

}

 

【开启禁用】

this.enabled = false;//禁用该脚本

if(GameManager.Instance.food)

 

private Text foodText;

foodText = GameObject.Find("FailText").GetComponent<Text>();

failText.enabled = false;

failText.enabled = true

 

[HideInspector]public Vector2 targetPos = new Vector2(1,1);

 

DontDestroyOnload(gameObject);//不要销毁

 

void HideBlack(){

dayImage.gameObject.SetActive(false);

}

Invoke("HideBlack",1)//经过一秒调用

 

【关卡变化】

Application.LoadLevel(Application.loadedLevel);//重新加载本关卡

 

void OnLevelWasLoaded (int sceneLevel){

Level++;

InitGame();//初始化游戏

}

 

【实例化】

GameManager放在预设里

在Main Camer添加一个新脚本Leader

public GameObjiect gameManager;

void Awake(){

if(GameManager.Instance==null)//等于空才进行实例化

GameObject.Instantiate(gameManager);

}

 

【音效播放】

public float minPitch = 0.9f;

public float manPitch = 1.1f;

public AudioSource efxSource;

 

public void RandomPlay(params AudioClip[] clips){

float pitch = Random.Range(minPitch,manPitch);

int index = Random.Range(0,clips.Length);

AudioClip clip = clips[index];

efxSource.clip =clip;

efxSource.pitch = pitch;

efxSource.Play();

}

 

转载于:https://my.oschina.net/u/4038194/blog/2963936

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Requires Unity 5.3.0 or higher. Make Skeleton & Vertex Animations right inside the Unity Editor. [New Online Manual] [v1.9.1] Constraints System Skele: Character Animation Toolssignificantly speeds up animator/indie's animation workflow in several ways: 1. Enable developers to make / modify character animations in UnityEditor. Reduce software switching and tedious import/export/split work 2. [BETA] Integrated Timeline editorGreatly accelerate authoring productivity for complex multi-character scenes (cutscenes / finishing moves / etc) 3. Mesh-Morpher tools to make blendshape-like animations without bones 4. Export skinned meshes and animations as DAE archive 5. Utilize the clips you bought from store, modify them to your needs, convert clip type, export to external softwares, etc. 6. Constraints system working in both edit-mode & game-mode. 7. Spline Editor to edit movement path. ******************* Humanoid rig needs special treatment:Please read the two FAQ posts: (1)How to Edit Humanoid clips? (2)Best workflow for Humanoid models? ******************* Main Features: 1. Make animation for your rigged characters with FK/IK support. flag, stick, dragon, ghost, mech, bird, fish, robot, human... you could manipulate ANY rigged models. 2. Modify animations. Modify Generic/Legacy animations directly; with our converter, you could also modify and export clips you bought from assetstore too. Modify and get the result immediately. 3. Make blendshape-like vertex animations directly in Unity Editor. 4. Integrated with Timeline Editor [BETA]. Edit the cutscene right inplace, and easily integrate with code/fx/audio/gui/etc. 5. Visualize the bone link, the vertices, and bone weights, etc. 6. Reduce the folder size, you don't need to include duplicate meshes for each animation. 7. Make/Save/Load poses on disk 8. Convert MuscleClip(Humanoid clip) to and fro Legacy/Generic clip 9. Generate RootMotion from RootBone curves 10. Export character mesh and character ani
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值