• 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 Misterok21 · Dec 04, 2015 at 07:28 PM · c#errorunity5

GameObject has undefined tag!

In m_MaterialHit = hit.collider.transform.tag; error!!! Code:

 using UnityEngine;
 using System.Collections;
 
 public class bl_FootSteps : Photon.MonoBehaviour
 {
 
     public bool CanUpdate = true;
     public AudioSource InstanceReference;
     public AudioClip[] m_dirtSounds;
     public AudioClip[] m_concreteSounds;
     public AudioClip[] m_WoodSounds;
     public float m_minSpeed = 2f;
     public float m_maxSpeed = 8f;
     public float audioStepLengthCrouch = 0.65f;
     public float audioStepLengthWalk = 0.45f;
     public float audioStepLengthRun = 0.25f;
     public float audioVolumeCrouch = 0.3f;
     public float audioVolumeWalk = 0.4f;
     public float audioVolumeRun = 1.0f;
     public PhotonView m_view;
     //private
     private bool isStep = true;
     private string m_MaterialHit;
 
     // Update is called once per frame
     void Update()
     {
         if (!CanUpdate)//if remote is not updated, only receives the RPC call (optimization helps)
             return;
         if (InstanceReference == null)
             return;
 
         RaycastHit hit;
         if (Physics.Raycast(transform.position, -Vector3.up, out hit, 10))
         {
             m_MaterialHit = hit.collider.transform.tag;
         }
         float m_magnitude = m_charactercontroller.velocity.magnitude;
         if (m_charactercontroller.isGrounded && isStep)
         {
             switch (m_MaterialHit)
             {
                 case "Concrete":
                     if (m_magnitude < m_minSpeed && m_magnitude > 0.75f)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Crouch", "Concrete");
                     }
                     else if (m_magnitude > m_minSpeed && m_magnitude < m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Walk", "Concrete");
                     }
                     else if (m_magnitude > m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Run", "Concrete");
                     }
                     break;
                 case "Dirt":
                     if (m_magnitude < m_minSpeed && m_magnitude > 0.75f)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Crouch", "Dirt");
                     }
                     else if (m_magnitude > m_minSpeed && m_magnitude < m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Walk", "Dirt");
                     }
                     else if (m_magnitude > m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Run", "Dirt");
                     }
                     break;
 
                 case "Wood":
                     if (m_magnitude < m_minSpeed && m_magnitude > 0.75f)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Crouch", "Wood");
                     }
                     else if (m_magnitude > m_minSpeed && m_magnitude < m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Walk", "Wood");
                     }
                     else if (m_magnitude > m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Run", "Wood");
                     }
                     break;
                 default:
                     if (m_magnitude < m_minSpeed && m_magnitude > 0.75f)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Crouch", "Concrete");
                     }
                     else if (m_magnitude > m_minSpeed && m_magnitude < m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Walk", "Concrete");
                     }
                     else if (m_magnitude > m_maxSpeed)
                     {
                         m_view.RPC("SyncSteps", PhotonTargets.All, "Run", "Concrete");
                     }
                     break;
             }            
         }
     }
 
     IEnumerator Crouch(string m_material)
     {
         if (InstanceReference.GetComponent<AudioSource>() == null)
             yield return null;
 
         isStep = false;
         switch (m_material)
         {
             case "Dirt":
                 InstanceReference.clip = m_dirtSounds[Random.Range(0, m_dirtSounds.Length)];
                 InstanceReference.volume = audioVolumeCrouch;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Concrete":
                 InstanceReference.clip = m_concreteSounds[Random.Range(0, m_concreteSounds.Length)];
                 InstanceReference.volume = audioVolumeCrouch;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Wood":
                 InstanceReference.clip = m_WoodSounds[Random.Range(0, m_WoodSounds.Length)];
                 InstanceReference.volume = audioVolumeCrouch;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
 
         }
         yield return new WaitForSeconds(audioStepLengthCrouch);
         isStep = true;
     }
 
 
 
     IEnumerator Walk(string m_material)
     {
         if (InstanceReference.GetComponent<AudioSource>() == null)
             yield return null;
 
         isStep = false;
         switch (m_material)
         {
             case "Dirt":
                 InstanceReference.clip = m_dirtSounds[Random.Range(0, m_dirtSounds.Length)];
                 InstanceReference.volume = audioVolumeWalk;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Concrete":
                 InstanceReference.clip = m_concreteSounds[Random.Range(0, m_concreteSounds.Length)];
                 InstanceReference.volume = audioVolumeWalk;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Wood":
                 InstanceReference.clip = m_WoodSounds[Random.Range(0, m_WoodSounds.Length)];
                 InstanceReference.volume = audioVolumeWalk;
                 InstanceReference.GetComponent<AudioSource>().Play();
                 break;
 
         }
         yield return new WaitForSeconds(audioStepLengthWalk);
         isStep = true;
     }
 
     IEnumerator Run(string m_material)
     {
         if (InstanceReference.GetComponent<AudioSource>() == null)
            yield return null;
 
         isStep = false;
         switch (m_material)
         {
             case "Dirt":
         InstanceReference.clip = m_dirtSounds[Random.Range(0, m_dirtSounds.Length)];
         InstanceReference.volume = audioVolumeRun;
         InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Concrete":
         InstanceReference.clip = m_concreteSounds[Random.Range(0, m_concreteSounds.Length)];
         InstanceReference.volume = audioVolumeRun;
         InstanceReference.GetComponent<AudioSource>().Play();
                 break;
             case "Wood":
         InstanceReference.clip = m_WoodSounds[Random.Range(0, m_WoodSounds.Length)];
         InstanceReference.volume = audioVolumeRun;
         InstanceReference.GetComponent<AudioSource>().Play();
                 break;
 
         }
         
         yield return new WaitForSeconds(audioStepLengthRun);
         isStep = true;
     }
 
     [PunRPC]
     void SyncSteps(string t_corrutine,string m_material)
     {
         StartCoroutine(t_corrutine,m_material);
     }
 
     public void OffUpdate()
     {
         CanUpdate = false;
     }
     public CharacterController m_charactercontroller
     {
         get
         {
             return this.transform.root.GetComponent<CharacterController>();
         }
     }
 }
 
 


Comment
Add comment · Show 1
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 Radical · Sep 02, 2017 at 09:08 AM 0
Share

This was solved. See my comment by (Radical) in http://answers.unity3d.com/questions/39557/unityexception-gameobject-has-undefined-tag-xcode.html?childToView=1401768#answer-1401768

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

41 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

Related Questions

I am trying to offset the camera from the player at all times even if the player moves. 0 Answers

error CS0201 1 Answer

Help with error in unity. 1 Answer

How to keep dropdown values after a scene switch or change them in a script 2 Answers

error CS0103 rb doesn't exist in the current context, ligne 8 and 15 , can't fix it 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