Question by
mantas1007 · Jul 22, 2017 at 08:38 AM ·
script.
error CS0118: `TreeHealth' is a `type' but a `variable' was expected
using UnityEngine; using System.Collections;
public class MeleeSystem : MonoBehaviour {
public int MinDamage = 25;
public int maxDamamge = 50;
public float weaponRange = 3.5f;
public Camera FPSCamera;
private void Update()
{
Ray ray = FPSCamera.ScreenPointToRay(new Vector2(Screen.width / 2, Screen.height / 2));
RaycastHit hitInfo;
if (Input.GetKeyDown(KeyCode.Mouse0))
{
if (Physics.Raycast(ray, out hitInfo, weaponRange))
{
if (hitInfo.collider.tag == "Tree")
{
TreeHealth = hitInfo.collider.GetComponentInParent<TreeHealth>();
AttackTree();
}
}
}
}
private void AttackTree()
{
}
}
Comment
Answer by bart1259 · Aug 03, 2017 at 01:34 AM
TreeHealth = hitInfo.collider.GetComponentInParent<TreeHealth>();
is the equivalent of saying
int = 4;
You never game the name of a variable
int a = 4
in your case, the solution would look like this:
TreeHealth treeHealth = hitInfo.collider.GetComponentInParent<TreeHealth>();
Your answer
![](https://koobas.hobune.stream/wayback/20220612130846im_/https://answers.unity.com/themes/thub/images/avi.jpg)