#How do I reference the character?
1 messages · Page 1 of 1 (latest)
make a function on the car that accepts the player reference as a parameter
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)
I won't use it often but I will try that
But the cards are put by the player and each card must have a different script so how do I insert the parameter from outside?
When you call a function, you provide the parameter
myCard.ExecuteAction(thePlayer);```
I dont know how to find the function from the outside if I dont know the script's name
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
Each card does something different so they need different scripts no?Tho I can name the function the same for all
When did I say "don't use different scripts"?
I said use a base class and inheritance and/or an interface
that implies different scripts
I think you're missing some C# basics here.
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/object-oriented/inheritance
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/object-oriented/polymorphism
https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/types/interfaces
My computer crashed
I lost the video
I will try looking at interfaces
This is the video with the player choosing the cards, each card as I said has a different script in it that will do something, tho I need to reference the character.
I can't reference the character because I can't drag it in the script when it is in the card prefab.
So I should what you provided me to be able to reference it right?
The player should reference the card that you instantiate from the prefab, and pass a reference to itself as a function parameter as needed.
I already know what your issue is, and the video doesn't really help anything
I am able to reference the card but I can't get the script component because each card will have a different script, thus I tought of referencing the character
I dont know how to get those components if I dont know which script it will be
It might work
it will work
Thanks, I will try those
Can I pass a GameObject to an interface as a parameter?
The same way you pass any other object as a parameter to any function
Thanks then I understood them
You probably wouldn't want to use GameObject though
I am now ready
you would use your Player script or whatever you actually need
I will pass a script with the stats then
thanks