Author Topic: [Solved] About drag and drop system probelm. Thanks ArenMook!  (Read 2718 times)

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Firstly, thanks for the great job on NGUI. It helps me a lot.
Here is my problem.
When I tried to use the drapdropitem system that you provided in , that is example 11.
However, I discovered that the item after dropped was not the actual side for the prefab(item).
It is because the item is the child of the surface.
Can anyone help me that I want any item dropped on the surface can always be the actual size of that?

Also, I hope that the item dropped can be let user to select the rotation(facing direction) of it.
How can I do?
Anyone would be greatly appreciated if anyone can help me to solve the above request(need).

I would try to introduce this great work to my friends too.
« Last Edit: March 12, 2014, 04:41:19 AM by Tomleung »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
ExampleDragDropItem script instantiates the prefab using NGUITools.AddChild (line 29 of ExampleDragDropItem.cs). AddChild resets the scale to (1, 1, 1). If you want the scale to be the same as it is in the prefab, add this line right after:
  1. child.transform.localScale = dds.transform.localScale;
Note that this is an Example script. It's meant to be modified to suit your needs.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Thank you! I would try it.

I would ask If I have any further questions.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
ExampleDragDropItem script instantiates the prefab using NGUITools.AddChild (line 29 of ExampleDragDropItem.cs). AddChild resets the scale to (1, 1, 1). If you want the scale to be the same as it is in the prefab, add this line right after:
  1. child.transform.localScale = dds.transform.localScale;
Note that this is an Example script. It's meant to be modified to suit your needs.

I discover that if the drag and drop surface is bigger, the item dropped on this surface is bigger too.
How to solve it that I want the item would always be one size only, that is the own size of the prefab.

Sorry for this because I am the newee of using unity. Thanks again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Replace "NGUITools.AddChild" with a simple "(GameObject)Instantiate". Check Unity's documentation on Instantiate: http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Replace "NGUITools.AddChild" with a simple "(GameObject)Instantiate". Check Unity's documentation on Instantiate: http://docs.unity3d.com/Documentation/ScriptReference/Object.Instantiate.html

Thanks for your reply.
What I want to know further is that, how to write Instantiate code in detail in this situation such as the position of the prefab.
Just replace "NGUITools.AddChild" with "(GameObject)Instantiate" is not successful.
Do I need to change any coding for this purpose?
Thanks again.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Please consult the Unity's documentation I linked. It has a few examples on how to use it.

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
I have known that how the "Instantiate(projectile, transform.position, transform.rotation)" coding works already in the last few weeks.
Just I do not know how I should write on the "transform.position" this part.
Moreover, the codes right after in that script also set up the transform of the item instantiated, so I do not know how to change these so that it can do what I want.

This is my difficulties to let you know and I hope that you can help me.
Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
  1. Instantiate(projectile, dds.transform.position, dds.transform.rotation);

Tomleung

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 44
    • View Profile
Thanks. It seems that it works.
It seems that I need to learn a lot futher.
Anyway, great job and I like NGUI!