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 joemdev · Aug 12, 2016 at 03:21 PM · c#scripting problemscripting beginnerscriptingbasics

Help with ontrigger enter and exit with UI Display appear and disappear

Ok so I am having a lot of trouble with this script I've written for my game. I'm almost done with it and this is one of the last pieces of the puzzle. I have a first person maze game, and I want the player to interact with a game object that ends up being a game point if the question is answered correctly. I only want the UI Panel to come up if the player enters the collider of the game object (game point). Then once the UI Panel comes up I want them to be able to answer the question asked by either keying in Y for yes or N for no. That or choosing a Yes button or a No button. I feel like i'm really close with my script but I keep getting this error (posted below with script) can anyone help me please.

Static member `UnityEngine.GameObject.FindGameObjectWithTag(string)' cannot be accessed with an instance reference, qualify it with a type name instead

script is listed below

using UnityEngine; using UnityEngine.UI; using UnityEngine.SceneManagement; using System.Collections;

public class QuestionsManager : MonoBehaviour { public GameObject Question1;

 // Use this for initialization
 void Start () 
 {
      Question1.FindGameObjectWithTag ("Level1Q1").SetActive = false;

 }
 

 void OnTriggerEnter()
 {
     Question1.FindGameObjectWithTag ("Level1Q1").SetActive = true;

 }

 void Update()
 {
     if (GetComponent<Collider>().gameObject.tag == "Level1Q1" && Input.GetKeyDown (KeyCode.N)) {
         Debug.Log ("That is the correct answer");
         Question1.FindGameObjectWithTag ("Level1Q1").SetActive = false;

     } else if (GetComponent<Collider>().gameObject.tag == "Level1Q1" && Input.GetKeyDown (KeyCode.Y)) {
         SceneManager.LoadScene ("WrongAnswerLevel1Q1");
     }
 }

 void OnTriggerExit()
 {
     Question1.FindGameObjectWithTag ("Level1Q1").SetActive = false;
 }

}

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

Answer by Zoogyburger · Aug 13, 2016 at 11:40 PM

Try this instead:

 using UnityEngine;
  using UnityEngine.UI; 
 using UnityEngine.SceneManagement; 
 using System.Collections;
 
 public class QuestionsManager : MonoBehaviour { public GameObject Question1;
 
     // Use this for initialization
     void Start () 
     {
         Question1 = GameObject.FindGameObjectWithTag ("Level1Q1");
         Question1.SetActive (false);
     }
 
     void OnTriggerEnter()
     {
         Question1 = GameObject.FindGameObjectWithTag ("Level1Q1");
         Question1.SetActive (true);
     }
     void Update()
     {
         if (GetComponent<Collider>().gameObject.tag == "Level1Q1" && Input.GetKeyDown (KeyCode.N)) {
             Debug.Log ("That is the correct answer");
             Question1 = GameObject.FindGameObjectWithTag ("Level1Q1");
             Question1.SetActive (false);
         } else if (GetComponent<Collider>().gameObject.tag == "Level1Q1" && Input.GetKeyDown (KeyCode.Y)) {
             SceneManager.LoadScene ("WrongAnswerLevel1Q1");
         }
     }
     void OnTriggerExit()
     {
         Question1 = GameObject.FindGameObjectWithTag ("Level1Q1");
         Question1.SetActive (false);
     }

}

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why when using get; set; in one script i'm getting null in other script that use it ? 1 Answer

Can someone explain calling other scripts in C#? 2 Answers

Quick code help! (c#) 2 Answers

Spawning 3D Objects according to Data at JSON Matrix 0 Answers

I need some help with my high score.,I need help with my highsore. 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