- Home /
How do I move/copy functions from one script to another while playing?
I'm making a card game and I'd like there to be an ability to copy all card effects from one card to another, how would I do that ?
Search google for these terms: scriptable object,delegates & events,or simply reference your script from other card to new card script. Simpliest possible example of referencing to other script.
public int CardValue; public $$anonymous$$yCardScript ScriptToGetInfoFrom; CardValue = ScriptToGetInfoFrom.CardValue; < when you do that you will pull Card value from other card and assign such value to this script/card CardValue.
Where $$anonymous$$yCardScript is the Exact name of your script on other card and ScriptToGetInfoFrom can be any name you like.
hi ,
Search for inheritence. when using inheritence you the class that inherit from a parent class will have all the parent effect's as well.
hmmm maybe you dont fully understand c# or how it's object oriented program$$anonymous$$g works. you pry wouldnt "move" a function. you would have a reference to the gameobject within that the function that it effcts. you can use the "destroy(script reference);" to destroy a script and "addComponent(name of script); "to add a script to a gameobject.
Good day.
As toddisarockstar says, you dont "move" functions, funcitons are not int he scene, are not objects, are not "real"....
They are just process. If you want objectA have the Power1, then you runt the function power1 refered top objectA
Power1(ObjectA);
Or you can do it for object B
Power1(ObjectB);
Objects and code are in different "reality planes". When you attach a script to an object, you are making that object DO some things. Ofcourse you can make any other objects do the same things...
Answer by jandd661 · Sep 15, 2018 at 12:50 PM
Greetings, Is this for the Player in the game? Or for you during development?
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Inheritance with enemies 1 Answer
How do I call an DontDestroyOnLoad function on UI text 2 Answers