hello and welcome I'm your code monkey
in this video we're considering to make
a tool tip in unity we're going to take
our tool tip and create a item stats
window with various text fields and
images let's begin
so over here is the tooltip we have done
so far it is great for displaying simple
text to the player like the description
of what each button does and extra
information on each field as you can see
it follows the mouse and we can update
it in real time now in this video we
want to reuse some of the code from
distal tip to create a complex tone tip
to shostats
of these items in here so let's start
off by making the complex tooltip in the
editor we're going to duplicate our
original tooltip comedy tooltip item so
the first thing we need is a label for
our name then we're also going to have a
description of each item now we're going
to position it going under the mouse so
our tooltip is anchored on the lower
left side and now for this one let's
anchor it on the upper left side
all right so this is the layout we're
going with we have an item name then we
have an atom description a image for the
item and a bunch of stats that won't be
different between each item okay so with
our total created in the editor now
let's take care of our class in order to
do it we're going to start off by
duplicating the total class that way we
can reuse some code okay so we now have
this class and now in here the code that
we can reuse is the code for following
the mouse and to make sure it does not
leave the screen the whole difference
here is our tool tip was anchored on the
lower left side and now we are anchoring
on the upper left side so in here
instead of anchor position y plus we do
a minus so just like that we should have
our item stats tooltip correctly
following the mouse now in the awake
let's grab the reference to the various
text fields okay so these are the
various fields we have we have the name
description and the various stats we no
longer need to update in real time so we
can remove this and on our show tooltip
let's start off by making one where we
only show the item name so start off
things very simple in here we just set
the name text text to be the item name
okay we're not going to resize the
background and here make the static
version of this function which is just
like this okay so our tooltip should be
working for changing the item name so we
can now go into the window in order to
test this is the window that I have set
up for testing it is a very basic window
it just has some buttons which function
and examine like these ones and on each
button I have a simple component that
contains the information out of each
item this is the component that contains
the information from each item it has a
sprite a name description and these
stats some script on the window let's
first test it by using the tooltip item
stats and add a tooltip let's add it to
the first button
and just say test item name okay so I
see if our custom complex tooltip shows
up when we pass the mouse over the first
button okay here's the scene and there's
the own tooltip still working perfectly
fine and now when we pass the first
button yep there you go there's our new
complex tooltip being shown you can see
that it has the test item name it has
the layout we set and everything is
working correctly all right so now
obviously let's fill up the rest of the
fields so we're going to change our show
tooltip function now in here we need
let's first receive a sprite for each
item sprite then we get the item name
then a string for the item description
and then in for the stats so in here
let's set all of our fields where's the
name text and the description text okay
so we now have our function receiving
all the information that it needs so
let's just update our static function
and just like that our tooltip is now
receiving all the information it needs
so now let's go into the window items
and again here in the editor just for
testing I've had the item info component
which contains all these fields
so let's grab this for each button okay
so we are cycling through our six
buttons we grab the item info that is
attached as a component to each of them
and we add the tooltip onto that button
using that items info all right so let's
see if all of them are correctly showing
their info okay so here we are and again
the old tooltip still works perfectly
fine and now when I pass over in item
yep there you go there's all of these
stats of each item being correctly
updated it has an item name a
description a image and the various
stats none of them are
dating correctly so as you can see we've
reused the code to follow the mouse and
keep the window on the screen which
allowed this to make this complex
relative very quickly and as you can see
all the elements of the dynamic tooltip
were created very simply so we could
easily swap out the stats for bars
instead of showing numbers so there you
have it we took some code from our
normal tooltip and made a complex item
tooltips with multiple fields and images
as always you can download the project
files in utilities from unity code
monkey comp if you have any questions
post them in the comments and I'll do my
best answer them subscribe for more
videos and I'll see you next time