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 /
avatar image
0
Question by eldsoki · Jun 18, 2017 at 08:58 PM · public static

please,help me with script

please, help me it give me error " Assets/script/interact.cs(43,43): error CS1061: Type Door[]' does not contain a definition for ChangeDoorState' and no extension method ChangeDoorState' of type Door[]' could be found. Are you missing an assembly reference?"with this line of code hit.collider.GetComponents().ChangeDoorState (); and I make it puplic void in the "door" script , please help me

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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mraction2012 · Jun 18, 2017 at 09:00 PM

hit.collider.GetComponent().ChangeDoorState();

Comment
Add comment · 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
0

Answer by eldsoki · Jun 18, 2017 at 09:04 PM

this is my full script using UnityEngine; using System.Collections.Generic; using UnityEngine.UI ;

public class interact : MonoBehaviour { public string interactbutton;

 public float interactdistance = 3f;
 public LayerMask interactlayer; // filter

 public Image interacticon; // picture to show interaction
 public bool isinteracting;
  
 // Use this for initialization
 void Start () {
     //set interact icon to be invisible
     if (interacticon != null)
     {
     
         interacticon.enabled = false;
     }
 }
 
 // Update is called once per frame
 void Update ()
 {
     Ray ray = new Ray (transform.position, transform.forward);
     RaycastHit hit;
     //shot a ray
     if (Physics.Raycast (ray, out hit, interactdistance, interactlayer))
     {
         //check if we are not interacting
         if (isinteracting == false) 
         {
             interacticon.enabled = true;
             // if we press the interaction button
             if (Input.GetButtonDown (interactbutton)) 
             {
                 // if it is a door
                 if (hit.collider.CompareTag ("Door"))
                 {
                     //open the door
                     hit.collider.GetComponents<Door>().ChangeDoorState();
                 }
             }
         }
     } 
     else
     {
         interacticon.enabled = false;
     }
 }

}

Comment
Add comment · Show 1 · 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 Mraction2012 · Jun 18, 2017 at 09:13 PM 0
Share

can u show that Door script?

avatar image
0

Answer by Cherno · Jun 18, 2017 at 11:44 PM

In this line:

 hit.collider.GetComponents<Door>().ChangeDoorState();

You use the GetComponents command, which returns an array of all found Components of the specified Type. Keeping this in mind, the error message tells you exactly what you need to know: The array of Type Door[] itself doesn't have a function "ChangeDoorState". Only the Type "Door" has this, so you have to first access one of the array's elements, like this:

     hit.collider.GetComponents<Door>()[0].ChangeDoorState();

However, since I assume that no collider will have more than one Door script on it, it's probably better to use the GetComponent command:

         hit.collider.GetComponent<Door>().ChangeDoorState();
Comment
Add comment · 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

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

67 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

Related Questions

object reference problem 1 Answer

Static member cannot be accessed 2 Answers

How can I reference a different public static variable in different instances of a prefab? 1 Answer

How do I access a boolean from another class in c#? 1 Answer

the most RESOURCE EFFICIENT way of referencing 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