Question by
soulstealrichardson · Apr 19, 2020 at 04:39 AM ·
prefabcomponentvalues
Can't access a value on a component of a script I made for a prefab.
This is on the Prefab
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class CardDisplay : MonoBehaviour
{
public Card card;
public TextMeshProUGUI _title;
public TextMeshProUGUI _description;
public TextMeshProUGUI _flavor;
public Image _artwork;
protected int _atack;
protected int _block;
public CardDisplay(Card card)
{
// Creating a constructor to create force the input of a card.
card = this.card;
}
void Start()
{
_title.text = card.title;
_description.text = card.description;
_flavor.text = card.flavorText;
_artwork.sprite = card.artwork;
_atack = card.atackPower;
_block = card.defencePower;
}
}
This is on an empty.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class CardHandler : MonoBehaviour
{
public GameObject PrefabOfCard;
public Vector3 SplayedCardsUI;
void Start()
{
DrawCard(1);
}
void DrawCard(int _numberOfCards)
{
while(_numberOfCards>=0)
{
GameObject _card = Instantiate(PrefabOfCard, SplayedCardsUI, Quaternion.identity);
Component _placeToSetCardsValues = _card.GetComponent<CardDisplay>();
_placeToSetCardsValues.Title;
_numberOfCards--;
}
}
}
But the error I'm getting is: Assets\Card Scripts\CardHandler.cs(21,36): error CS1061: 'Component' does not contain a definition for 'Title' and no accessible extension method 'Title' accepting a first argument of type 'Component' could be found (are you missing a using directive or an assembly reference?)
I can show you an image of the script in the editor.
Comment