UNITY3D-RPG Project Study notes (12)

Source: Internet
Author: User

The early realization of the basic backpack storage functions, and now began to build backpack items mobile and Exchange functions, the specific ideas are as follows:

① reads the lattice information of the existing item.

② the mobile target location (that is, the tag on your surface):

If the tag of surface is empty, the local coordinates of the item are zeroed;

If your surface's tag is not empty, there are a few things to consider:

1.Tag for backpack lattice: indicating that the mobile location is empty lattice, so that the object information assigned to the target, clear the existing information can be;

2.Tag for backpack items: indicating that the mobile location for the item lattice, the two grid information exchange can be;

3.Tag for other items: Describes unconventional movements, zeroing out the displacement information of the item.

The script is added as follows:

Class Inventory_item

{

void Resetposition ()

{

Tranform.localpostion = Vector3.zero;

}

protected override void Ondragdroprelease (Gameobject surface)

{

Base. Ondragdroprelease (surface);

if (surface! = null)

{

if (surface. Tag = = "Inventory_grid")

{

if (surface = This.transform.parent.gameObject)

{

Resetposition ();

}

Else

{

Inventorygrid Nowgrid = this.transform.parent.getcompnent<inventorygird> ();

This.tranform.parent = Surface.transform;

Resetposition ();

Inventorygrid Newgrid = surface. Getcompnent<inventorygrid> ();

Newgrid. SetId (Nowgrid.id,nowgrid.num);

Nowgrid. Clearinfo ();

}

}

else if (surface. Tag = = "Inventoryitem")

{

Inventorygird grid1 = this.transform.parent.getcompnent<inventorygrid> ();

Inventorygrid Grid2 = surface.transform.parent.getcompnent<inventorygrid> ();

int id = grid1.id; int num = Grid1.num;

Grid1. SetId (Grid2.id,grid2.num);

Grid2. SetId (Id,num);

}

Else

{

Resetpositon ();

}

}

Else

{

Resetposition ();

}

}

}

UNITY3D-RPG Project Study notes (12)

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.