Hey there! I’m very new to Unity and coding and I’m working on my first little game project.
My game revolves around placing character cards into locations and then the location and that character card deal damage to one another at a set rate (independent of one another) until one of them runs out of health.
I have two questions:
-
Currently the location code has a serialized field to input the insertedCard scriptable object. I can do that manually myself through the unity interface just fine but how do I insert a gameobject into the field during gameplay through drag and drop?
-
How do I properly reference the stats of the insertedCard within my location script? Snippet of my code below for example:
private void GetCardStats()
{
if (insertedCard != null)
{
float cardInterval = insertedCard.GetComponent<CardStats>().cardInterval;
float cardDamage = insertedCard.GetComponent<CardStats>().cardDamage;
float cardHealth = insertedCard.GetComponent<CardStats>()._cardHealth;
}
}
private void StartTimer()
{
GetCardStats();
InvokeRepeating("TakeDamage", 1f, cardInterval);
InvokeRepeating("DealDamage", 1f, locationTimerInterval);
StartCoroutine(EndCombat());
}
Thanks for any help you can offer! I’m sure these are extremely basic questions.