Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by ReggieBeRetro · Jun 29, 2016 at 10:27 PM · c#gameobjectcolliderhittype

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;
                 }
 
             }
         }
     }
 }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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>();
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ReggieBeRetro · Jun 29, 2016 at 11:47 PM 0
Share

oh yes thx. I should have been able to figure that out. smh.. u saved me a headache.

avatar image ReggieBeRetro · Jun 29, 2016 at 11:50 PM 0
Share

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.

avatar image jgodfrey ReggieBeRetro · Jun 30, 2016 at 02:02 AM 0
Share

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...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

180 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to make an object move to the direction in which the user faces using vr gaze interaction? 1 Answer

collider.gameObject.GetComponent doesn't have correct values yet it has the correct name 0 Answers

Status Effect Help 0 Answers

Getting collision for individual gameobjects in an array and changing properties of other gameobjects from that array 0 Answers

How to make a floppy object 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges