Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 JPCannon · May 12, 2014 at 08:39 PM · mesh

Show object with tag after button press

Hi, I look in many posts here and try lot of options but nothing works. I have spaceship with script. It have child with tag "Plomien" (its Flame in Polish). I want to show that Flame when I go forward. Pls help. One by one i get error "NullReferenceExeption: Object Reference not set to an instance of an object".

 using UnityEngine;
 using System.Collections;
 
 public class Sterowanie : MonoBehaviour {
 
     public float predkosc;
     public float maksymalnaPredkosc = 10f;
     private float predkoscSkretu;
     private float predkoscZwrotu;
     private GameObject plomien;
 
     // Use this for initialization
     void Start () {
         predkosc = 0;
         predkoscSkretu = 0.2f;
         predkoscZwrotu = 0.2f;
         rigidbody.useGravity = false;
     //    GameObject.FindWithTag("Plomien").SetActive(true);
     //    plomien.activeSelf;
     }
 
     void FixedUpdate() 
     {
         //stala predkosc zalezna od zmiennej predkosc
         transform.Translate (0, 0, predkosc);
         //przyśpieszanie i maksymalna predkosc
         if (Input.GetKey(KeyCode.A) && predkosc < 10f) {
             Debug.Log("dzialaA");
             predkosc = predkosc+0.1f;

//HERE IS MY PROBLEM. PLS HELP!

             plomien = GameObject.FindGameObjectWithTag("Plomien");
             MeshRenderer p = plomien.GetComponent<MeshRenderer>();
             p.enabled = true;


         //    GameObject[] f1 = GameObject.FindGameObjectsWithTag("Plomien"); 
         //    foreach(GameObject f in f1)
         //    {
         //        f.GetComponent<MeshRenderer>().enabled = true;
         //    }
         }
         //zwalnianianie i predkosc minimalna
         if (Input.GetKey(KeyCode.Z) && predkosc > 0f) {
             Debug.Log("dzialaZ");
             predkosc = predkosc-0.1f;
         }
 
         //obrót w góre i dół zrobić dwoma punktami. Niech dziób unosi się w góre, a tył statku w dół
 
         if (Input.GetKey(KeyCode.UpArrow)) {
             transform.Rotate(Vector3.left * predkoscSkretu);
         }
         
         if (Input.GetKey(KeyCode.DownArrow)) {
             transform.Rotate(Vector3.right * predkoscSkretu);
         }
 
         if (Input.GetKey(KeyCode.LeftArrow)) {
             transform.Rotate(Vector3.forward * predkoscSkretu);
             transform.Rotate(Vector3.down * predkoscZwrotu);
         }
 
         if (Input.GetKey(KeyCode.RightArrow)) {
             transform.Rotate(Vector3.back * predkoscSkretu);
             transform.Rotate(Vector3.up * predkoscZwrotu);
         }
     }
     
     // Update is called once per frame
     void Update () {
 
     }
 }
 
Comment
Add comment · Show 4
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 Vitor_r · May 12, 2014 at 08:51 PM 0
Share

If it is a NullReferenceExeption probably the code isn't finding an object with the "Plomien" tag.

Check if it's spelled correctly, and also use some Debug.Log to check what the "FindGameObjectWithTag" returns.

avatar image JPCannon · May 13, 2014 at 08:30 AM 0
Share

Debug Log give me Null. Spelling is right. If i change tag, I get error that unity didnt found object with this tag, so it can find this but see only Null.

http://ifotos.pl/zobacz/picturepn_enwsrse.png/

pls help, if you have better solution to do this, give me some.

avatar image Xitech_ · May 13, 2014 at 08:33 AM 0
Share

Again, as Vitor_r mentioned. A nullrefernce means that it has not found the object. The reference is missing ("The link"). Just like you create a shortcut on your desktop to: X:\Program Files ins$$anonymous$$d of C:\Program Files. X:\Program Files doesnt exist so the reference("the link/connection") is missing

avatar image JPCannon · May 13, 2014 at 01:58 PM 0
Share

So if i show here code and screen how it looks in unity, can someone give me example how to create good reference by tag, and how to correctly create gameobject.findwithtag("");?

0 Replies

· Add your reply
  • Sort: 

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

22 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

Related Questions

Trouble Creating a Procedural Mesh on a Rotated Game Object 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Cutting a Mesh Into Smaller Pieces 5 Answers

Problems with Transform.Find and GameObject.find 1 Answer

How to Change an Object's Mesh to another Object's Mesh via Code C# 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