Question by
Akuma-no-Tsubasa · Nov 12, 2015 at 07:48 PM ·
c#error message
[C#] implicit convert error
Hello,
I am getting the error "Assets/Scripts/Upgrades.cs(20,17): error CS0029: Cannot implicitly convert type 'string' to 'UnityEngine.UI.Text'". The corresponding script is the following:
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class Upgrades : MonoBehaviour {
public ClickScript click;
public Text itemInfo;
public float cost;
public int count = 0;
public int clickPower;
public string itemName;
private float baseCost;
void Start(){
baseCost = cost;
}
void Update(){
itemInfo = itemName + "\nCost: " + cost + "\nPower: +" + clickPower;
}
public void PurchasedUpgrade(){
if (click.Money >= cost) {
click.Money -= cost;
count++;
click.MoneyPerClick += clickPower;
cost = baseCost * Mathf.Pow(1.30f, count);
}
}
}
Comment
Best Answer
Answer by Jessespike · Nov 12, 2015 at 07:58 PM
iteminfo is a class (UI.Text). You want to assign the text property in the class (UI.Text.text).
itemInfo.text = itemName + "\nCost: " + cost + "\nPower: +" + clickPower;
Your answer
Follow this Question
Related Questions
StartCoroutine error message in C# 1 Answer
ForcedScopedThreadAttach 0 Answers
C# Greater Than or Equal To 1 Answer
Variable changing from other script does not work. 1 Answer
ArgumentNullException When using Collider2D.OverlapCollider() 1 Answer