I am trying to convert this javascript into c# and so far it’s going pretty good but i can’t fix this last part because it keeps saying this:
Error CS1503 Argument 3: cannot convert from ‘UnityEngine.RaycastHit’ to ‘float’
Error CS0119 ‘treeController’ is a type, which is not valid in the given context
this is the javascript
#pragma strict
var rayLength = 10;
private var treeScript : TreeController;
function Update()
{
var hit : RaycastHit;
var fwd = transform.TransformDirection(Vector3.forward);
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if(hit.collider.gameObject.tag == "Tree")
{
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent(TreeController);
if(Input.GetButtonDown("Fire1"))
{
treeScript.treeHealth -= 1;
}
}
}
}
and this is my converted c# script that has some problems:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class rayCastTree : MonoBehaviour {
public float rayLenght = 10;
public treeController treeScript;
public RaycastHit hit;
public Transform fwd;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
int rayLength = 10;
var fwd = transform.TransformDirection(Vector3.forward);
//var hit = ?????????????
if (Physics.Raycast(transform.position, fwd, hit, rayLength))
{
if (hit.collider.gameObject.tag == "Tree")
{
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent(treeController);
if (Input.GetButtonDown("Fire1"))
{
treeScript.treeHealth -= 1;
}
}
}
}
}