http://answers.unity3d.com/questions/8472/help-with-error-expression-denotes-a-type-where-a.html
Hello i am working on converting this script from java to c# i am almost there i have run into a error for which i cant find a solution.
from what i can see it looks correct but it is clearly not can anyone shed some light on the subject.
this is the error i get.
Assets/Scripts/RayCastChop.cs(21,115): error CS0119: Expression denotes a type', where a
variable', value' or
method group' was expected
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent(TreeCont); is the line that is giving me problems.
The original script can be found in this video as mentioned it was originally written in javascript. I have been told it is not good to mix languages and because i have started writing my game in c# i want to stick to c# and not cross languages.
https://www.youtube.com/watch?v=ZSbdzZVQWnI
using UnityEngine; using System.Collections;
public class RayCastChop : MonoBehaviour {
int rayLength = 10;
private TreeCont treeScript;
private PlayerControls playerAnim;
public Vector3 fwd;
void Update (){
RaycastHit hit;
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<TreeCont>(TreeCont);
//playerAnim = GameObject.Find ("Human_Model@Idle").GetComponent (PlayerControls);
if (Input.GetMouseButtonDown(0))
{
treeScript.treeHealth -= 1;
}
}
}
}
}
Answer by jgodfrey · Jun 29, 2016 at 11:16 PM
This...
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent<TreeCont>(TreeCont);
Should be...
treeScript = GameObject.Find(hit.collider.gameObject.name).GetComponent<TreeCont>();
oh yes thx. I should have been able to figure that out. smh.. u saved me a headache.
1 more to go. Now im getting a unassigned variable error for hit. why is that happening if i am declaring it? im a bit confused.
The "hit" reference here:
if(Physics.Raycast(transform.position, fwd, hit, rayLength))
should be:
if(Physics.Raycast(transform.position, fwd, out hit, rayLength))
Notice the "out" modifier...