Unity Store Demo Learning: Top View RPG game

Source: Internet
Author: User

All the footage and source code are from the Unity store instance top-down RPG Starter Kit, the demo is the best entry-level RPG game instance on the Unity store, little, perfectly formed, This is a good choice to figure out the various aspects of a standard RPG game.

Ps:demo write very advanced, do not see very understand, ready to study slowly.

Get a picture of the project.



This is a view angle (can adjust the angle of view) cartoon-style 3D role-playing game, with beautiful and cheerful background music, and the Beast of the monster, as if back to the junior high school when playing adventure Island online ~ ~, the amount, not nonsense, the main modules are as follows:

    • Game Main Menu Interface
    • Game character selection scene
    • Game Role Control
    • Camera control
    • Character Growth system
    • NPC Dialogue and Mission system
    • Skill System
    • Backpack system
    • Equipment system
    • Store system
    • Small map
    • Game Monster AI
    • Monster Drop and Pickup
    • Monster boss
    • Game HUD GUI
    • Music and sound
    • Archiving system
Lack map system, riding pet systemAnd Replica SystemHere's how to experience it one by one.
Game Main Menu Interface
Loaded with basic game scenes, lights, sky boxes, and main Menu interface GUI is mainly controlled by four scripts
Controltitlescene control camera movement and text effects Alphatext control starts with Blur to clear Newgamebutton start a new game Loadgamebutton load archive
Two of these buttons are implemented with the Guitexture control, not the Ugui or legacy UI
<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);;}

Game character selection scene


It is still loaded with basic game scenes, lights, sky boxes, and main Menu interface GUI, as well as game characters.
This scene can create your own character, with Swords and mages two characters to choose from. Controlled by four scripts
Buttonok determines the role selection buttonselected used to toggle the role button Etenname gets the character input of the user Selectcharacter is used to render the selected role, hides the unchecked role, the dynamically instantiated coordinate point is marked in the scene mean empty object
Where dynamic instantiation of a role is a key point
public class Selectcharacter:monobehaviour {public gameobject[] hero; Your heropublic gameobject Buttonnext,buttonprev;  Button prev and button next[hideininspector]public int indexhero = 0; Index select Heroprivate gameobject[] heroinstance; Use of Keep Hero Gameobject when instantiate//use this for initializationvoid Start () {heroinstance = new gameobject[h Ero. Length]; Add array size equal hero Sizeindexhero = 0; Set default selected Herospawnhero (); Spawn hero to display current Selected//check if hero are less than 1, button next and Prev would Disappearif (hero. Length <= 1) {buttonnext.setactive (false); buttonprev.setactive (false);}} Check Show only selected Characterpublic void Updatehero (int. _indexhero) {for (int i=0; I
Game Role Control


It is still loaded with basic game scenes, lights, sky boxes, and the main menu GUI, as well as game characters, several NPCs, and monsters.
The role control has the following script, but here only the game walking, skill control
Herocontroller Control role Walk and recruit Spawnpointhero role spawn point and re-birth Areaskillcursor control group attack skill operating range Skillarea calculate group attack range and target number Animationmanager control character walk and attack animation
= = Code did not read t_t
Camera control


Camera angle of view can be adjusted to the top and normal near 3D mode, and the camera to follow the distance from the character can also freely adjust the main control script
Minimapcamera control camera target follow and mini map coordinate positioning Mouseorbit control view rotation and zoom
Where the rotation of the four-dollar number, very basic graphics
quaternion rotation = Quaternion.euler (y, x, 0); Vector3 Calpos = new Vector3 (0, 0,-distancelerp);p osition = rotation * Calpos + target.transform.position;transform.rotat ion = rotation;

Character Growth system
Role HP,MP and XP management and upgrade, attribute add-on managed by Playerstatus script
= = Code still not read t_t

NPC Dialogue and Mission system
Dialogue with NPC and succession
Npcsetup control the generation of NPCs and the interaction of dialog boxes
such as testing whether the task is completed and given rewards
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);D Ebug. Log ("Give"); break;}}}

Skill System
Skill system includes activation of skills, learning, adding dots, attribute bonus, skill shortcut keys
Controlled by the Playerskill script
= = Code still not read t_t

Backpack system
Manage backpack items, items can be dragged to the equipment window and skill Shortcut window
Equipment system
Controlled by script Item_data
public enum Equipment_type{null = 0, head_gear = 1, Armor = 2, Shoes = 3, accessory = 4, Left_hand = 5, Right_hand = 6, Tw O_hand = 7}

Store system
There are drug stores and equipment stores two scripts Item_data,item_obj,shopitemlist script control, a common class implementation of two stores instances
such as buying goods
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;}

Small map
Small maps are used for location overview and automatic navigation, which can be scaled by script Minimapsignsetup and Minimapcamera to control
Where to set the mark points for stores, characters, and monsters
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];}}

Game Monster AI
Monster AI includes monster tracking, attack and other behavioral control scripts
Detectarea detection and role collision Dropitem control Monster Drop Enemycontroller Control Monster Walk and attack Enemystatus control Monster Blood bar status Monster_data manage monster data
Monster tracking simply uses a straight line to move
Move to destinationif (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-= * Time.deltatime;controller. Move (Movedir*time.deltatime);

Monster Drop and Pickup
Monster Drop
public void Usedropitem () {for (int i = 0; i < Item_drop_list.count; i++) {Float Percentresult = Random.range (0,100); if (PE Rcentresult < 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);}}}

Monster boss
Bosses are pretty much the same as normal monsters, but they're a lot higher.
Game HUD GUI
Mainly the game head-up interface, including character Blood Bar, magic bar and experience bar, skill Shortcut Bar and System Menu control script
Bottombar draw Skill Shortcut Bar Commanmenu Draw System command bar, backpack, skill, outfit, status etc enemyhp draw enemy's blood strips Herostatusbar draw character hp,mp and Avatar
Not using Ngui or Ugui, all legacy GUI
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 ();

Music and sound
Unified music and sound management controlled by Soundmanager scripts
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 = = _soundna Me) {return i;} i++;} return i;}

Archiving system
The game can be archived at the designated location, and then can be read at the beginning of the game
but the script seems to have not found, do not know what to use storage files t_t
Ps:demo Watching is really pleasing ah, unfortunately not too understand, temporarily no ability to imitate, only slowly ~

Unity Store Demo Learning: Top View RPG game

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.