#How do I reference the character?

1 messages · Page 1 of 1 (latest)

tight lily
#

My character is in the scene, and the player can organize cards that affects this character.
The cards are a prefab so I can randomize them, but I cant reference the character just by dragging it in the public variable.Any ways to do this?

royal sparrow
#

make a function on the car that accepts the player reference as a parameter

twin dawn
#

GameObject.Find("CharacterName) will find you anything in the scene. References are obviously best, as this can lead to issues later (performance if used too often, confusion if objects have the same name)

tight lily
tight lily
royal sparrow
#
myCard.ExecuteAction(thePlayer);```
tight lily
royal sparrow
#

wdym you don't know the script's name? Aren't they all subclasses of a base Card class or something?

#

You should be using inheritance here or an interface

tight lily
tight lily
#

I lost the video

#

I will try looking at interfaces

tight lily
#

So I should what you provided me to be able to reference it right?

royal sparrow
#

I already know what your issue is, and the video doesn't really help anything

tight lily
tight lily
#

I dont know how to get those components if I dont know which script it will be

royal sparrow
#

I explained that above

#

Use an interface or polymorphism

tight lily
royal sparrow
#

it will work

tight lily
#

Thanks, I will try those

tight lily
royal sparrow
tight lily
royal sparrow
#

You probably wouldn't want to use GameObject though

tight lily
#

I am now ready

royal sparrow
#

you would use your Player script or whatever you actually need

tight lily
#

thanks