标签:unity
一下所有素材和源码都来自unity商店的实例 Top-Down RPG Starter Kit ,这个demo是unity商店上最好的入门级rpg游戏实例,麻雀虽小,五脏俱全,想要弄清楚一个标准的rpg游戏的方方面面,这个是很好的选择。
ps:demo写得很高深,看得不是很懂,准备慢慢研究。
来一张工程全貌图。
这是一个俯视视角(可以调整视角)的卡通风格3D角色扮演游戏,配着动听又欢快的背景音乐,还有那萌萌哒的怪物,仿佛又回到了初中时玩冒险岛online的时候~~,额,不废话,主要模块如下:
<span style="white-space:pre"> </span>void OnMouseUp() { this.guiTexture.texture = buttonNormal; Invoke("LoadScene",0.1f); } void OnMouseDown() { if(buttonSfx != null) AudioSource.PlayClipAtPoint(buttonSfx,transform.position); this.guiTexture.texture = buttonDown; } void LoadScene() { Application.LoadLevel(loadSceneName);; }
public class SelectCharacter : MonoBehaviour { public GameObject[] hero; //your hero public GameObject buttonNext,buttonPrev; //button prev and button next [HideInInspector] public int indexHero = 0; //index select hero private GameObject[] heroInstance; //use to keep hero gameobject when Instantiate // Use this for initialization void Start () { heroInstance = new GameObject[hero.Length]; //add array size equal hero size indexHero = 0; //set default selected hero SpawnHero(); //spawn hero to display current selected //check if hero is less than 1 , button next and prev will disappear if(hero.Length <= 1) { buttonNext.SetActive(false); buttonPrev.SetActive(false); } } //Check show only selected character public void UpdateHero(int _indexHero) { for(int i=0; i<hero.Length;i++) { //Show only select character if(i == _indexHero) { heroInstance[i].SetActive(true); }else { //Hide Other Character heroInstance[i].SetActive(false); } } } //Spawn all hero public void SpawnHero() { for(int i=0;i<hero.Length;i++) { heroInstance[i] = (GameObject)Instantiate(hero[i],transform.position,transform.rotation); } UpdateHero(indexHero); } }
Quaternion rotation = Quaternion.Euler(y, x, 0); Vector3 calPos = new Vector3(0, 0, -distanceLerp); position = rotation * calPos + target.transform.position; transform.rotation = rotation;
bool CheckConditionItem(int id,int amout) { for(int i =0;i<inventory.bag_item.Count;i++) { if(inventory.bag_item[i].item_id == id && inventory.bag_item[i].item_amount >= amout) { inventory.bag_item[i].item_amount -= amout; if(inventory.bag_item[i].item_amount <= 0) { inventory.bag_item[i].item_id = 0; } return true; } } return false; } void GiveReward(int id) { for(int i=0;i<questData.questSetting.Count;i++) { if(questID == questData.questSetting[i].questID) { inventory.GiveItem((int)questData.questSetting[i].itemIDReward.x,(int)questData.questSetting[i].itemIDReward.y); Debug.Log("Give"); break; } } }
public enum Equipment_Type{ Null = 0, Head_Gear = 1, Armor = 2, Shoes = 3, Accessory = 4, Left_Hand = 5, Right_Hand = 6, Two_Hand = 7 }
public Item Get_Item(int item_id){ int i = 0; bool isEnd = false; if(isEnd == false){ while(i < item_equipment_set.Count){ if(item_id == item_equipment_set[i].item_ID){ return item_equipment_set[i]; i = item_equipment_set.Count; isEnd = true; } i++; } } i = 0; if(isEnd == false){ while(i < item_usable_set.Count){ if(item_id == item_usable_set[i].item_ID){ return item_usable_set[i]; i = item_usable_set.Count; isEnd = true; } i++; } } i = 0; if(isEnd == false){ while(i < item_etc_set.Count){ if(item_id == item_etc_set[i].item_ID){ return item_etc_set[i]; i = item_etc_set.Count; isEnd = true; } i++; } } i = 0; if(isEnd == false){ while(i < item_gold.Length){ if(item_id == item_gold[i].item_ID){ return item_gold[i]; i = item_gold.Length; isEnd = true; } i++; } } return null; }
void TextureSetup () { if(signType == MinimapSignType.Player) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[0]; }else if(signType == MinimapSignType.Enemy) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[1]; }else if(signType == MinimapSignType.Boss) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[2]; }else if(signType == MinimapSignType.Npc) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[3]; }else if(signType == MinimapSignType.ShopWeapon) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[4]; }else if(signType == MinimapSignType.ShopPotion) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[5]; }else if(signType == MinimapSignType.SavePoint) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[6]; }else if(signType == MinimapSignType.Quest) { this.gameObject.renderer.material = MinimapSign.Instance.minimapSignMat[7]; } }
// Move to destination if(ctrlAnimState == ControlAnimationState.Move){ if(controller.isGrounded){ movedir = Vector3.zero; movedir = transform.TransformDirection(Vector3.forward*moveSpeed); } }else { movedir = Vector3.Lerp(movedir,Vector3.zero,Time.deltaTime * 10); } movedir.y -= 20 * Time.deltaTime; controller.Move(movedir*Time.deltaTime);
public void UseDropItem(){ for(int i = 0; i < item_Drop_List.Count; i++){ float percentResult = Random.Range(0,100); if(percentResult < item_Drop_List[i].percentDrop){ GameObject go = (GameObject)Instantiate(item_Obj_Pref,transform.position+(Vector3.up),Quaternion.identity); go.rigidbody.AddForce(new Vector3(Random.Range(-1,1)*1.5f*powerImpulse,1*3*powerImpulse,Random.Range(-1,1)*1.5f*powerImpulse),ForceMode.Impulse); Item_Obj item_obj = go.GetComponent<Item_Obj>(); item_obj.item_id = item_Drop_List[i].item_id; item_obj.SetItem(); if(item_obj.gold){ item_obj.gold_price = Random.Range(gold_min, gold_max); } } } }
GUI.BeginGroup(new Rect(posHPbar.x, posHPbar.y,sizeHPBar.x,sizeHPBar.y)); GUI.DrawTexture(new Rect(0,0, sizeHPBar.x ,sizeHPBar.y), hpBar); GUI.BeginGroup(new Rect(0,0,ConvertHP(sizeHPBar.x,maxHP,curHP),sizeHPBar.y)); GUI.DrawTexture(new Rect(0,0,sizeHPBar.x,sizeHPBar.y), hpCurrent); GUI.EndGroup(); GUI.EndGroup();
public void PlayingSound(string _soundName){ AudioSource.PlayClipAtPoint(sound_List[FindSound(_soundName)].audioClip, Camera.mainCamera.transform.position); } private int FindSound(string _soundName){ int i = 0; while( i < sound_List.Count ){ if(sound_List[i].soundName == _soundName){ return i; } i++; } return i; }
标签:unity
原文地址:http://blog.csdn.net/u012234115/article/details/46311237