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 Numonic · Dec 22, 2017 at 05:53 PM · clonemissingreferenceexception

Missing Component in a Clone

How do I add a missing component to a Clone object in Unity? I'm currently using C# for the programming language.

MissingComponentException: There is no 'AudioSource' attached to the "FootSolder(Clone)" game object, but a script is trying to access it. You probably need to add a AudioSource to the game object "FootSolder(Clone)". Or your script needs to check if the component is attached before using it.`enter code here`

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 [RequireComponent(typeof(AudioSource))]
 
 public class FootDoDamage : MonoBehaviour
 {
 
 
     GameManager gameManager;
     CharacterStats characterStats;
     PlayerController playerController;
     public Animator anim;
     public GameObject explosionPrefab;
 
     public AudioSource footExplosionSound;
 
 
     public EnemySight enemySight;
     public GameObject punchAttackObj;
     public GameObject kickAttackObj;
 
     public int footHealth = 100;
 
     void Start()
     {
 
         if(explosionPrefab ==null)
         {
             explosionPrefab = GetComponent<GameObject>();
         }
         
         if(footExplosionSound == null)
         {
             footExplosionSound = GetComponent<AudioSource>();
         }
         
         footExplosionSound = GetComponent<AudioSource>();
 
 
         if (anim == null)
         {
             anim = GetComponent<Animator>();
         }
 
         if (playerController == null)
         {
             playerController = GetComponent<PlayerController>();
         }
 
         if (enemySight == null)
         {
             enemySight = GetComponent<EnemySight>();
         }
 
         if (gameManager == null)
         {
             gameManager = GetComponent<GameManager>();
 
         }
 
         if (characterStats == null)
         {
             characterStats = GetComponent<CharacterStats>();
 
         }
 
 
 
     }
 
     // Update is called once per frame
     void Update()
     {
 
     }
 
     public void HidePunchAttack()
     {
         enemySight.anim.SetBool("attackcombo", false);
         punchAttackObj.SetActive(false);
     }
 
     public void ShowPunchAttack()
     {
         enemySight.anim.SetBool("attackcombo", true);
         punchAttackObj.SetActive(true);
     }
 
     public void HideKickAttack()
     {
         enemySight.anim.SetBool("attackcombo", false);
 
         kickAttackObj.SetActive(false);
     }
 
     public void ShowKickAttack()
     {
         enemySight.anim.SetBool("attackcombo", true);
 
         kickAttackObj.SetActive(true);
     }
   
     public void FootTakeDamage()
     {
         if(this.gameObject != null)
         {
             // Taking away health based on sword attack
             footHealth -= 50; // take away 50 from attack
             
             anim.SetBool("hit", true);
             anim.SetBool("attackcombo", false);
             anim.SetBool("walk", false);
             gameObject.SetActive(true);
 
             if (footHealth <= 0)
             {
                 anim.SetBool("hit", false);
                 anim.SetBool("defeated", true);
                 CancelInvoke("FootSolder");
 
                 StartCoroutine(HideFootSolder()); // Call the coroutine here and hide object
 
                 enemySight.navMeshAgent.updateRotation = false;
                 enemySight.navMeshAgent.angularSpeed = 0;
                 enemySight.navMeshAgent.isStopped = true;
                //enemySight.navMeshAgent.enabled = false;
             }
         }
     }
     // Hide object in Coroutine instead of out right destroying it and causing errors.
     IEnumerator HideFootSolder()
     {
 
         yield return new WaitForSeconds(2f);
         footExplosionSound.Play();
 
         Instantiate(explosionPrefab, transform.position, Quaternion.identity);
         gameObject.SetActive(false);
         footExplosionSound.Stop();
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.tag == "lkatana" || other.tag == "rkatana" || other.tag == "leorfootattack")
         {
             FootTakeDamage();
             // To Do Get the Blocked Colliders to turn off when players are defeated
             print("Leo is hitting FootSolder.");
         }
         else
         {
 
 
         }
     }
 
   
 }
 
 


 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityStandardAssets.Utility;
 
 public class GameManager : MonoBehaviour {
 
 
     public Transform []spawnPosition;
     public GameObject footPrefab; //footPrefab2, //footPrefab3;
    // private GameObject FootSolder(Clone);
     public List<Transform> enemiesSpawned = new List<Transform>();
 
     public FollowTarget followTarget;
     public CameraFollow cameraFollow;
     public GameObject blockColliders;
 
     public bool wave1;
     public bool wave2;
     public bool wave3;
 
     public int spawnRateMax = 6;
     public int spawnRateMin = 1;
     public float spawnTime = 3f;
 
     public float countdown;
     private float currentTime;
 
 
     void Awake ()
     {
         currentTime = countdown;
 
        // InvokeRepeating("Wave1Attack", spawnTime, spawnTime);
 
         if(cameraFollow == null)
         {
             cameraFollow = GetComponent<CameraFollow>();
 
         }
 
 
         if(blockColliders ==null)
         {
             blockColliders = GetComponent<GameObject>();
         }
 
 
         if(followTarget == null)
         {
             followTarget = GetComponent<FollowTarget>();
 
         }
     }
     
     // Update is called once per frame
     void Update ()
     {
         /*
         countdown -= Time.deltaTime;
 
         if(countdown <= 0)
         {
             wave1 = true;
              Wave1Attack();
 
             // camera stops following player when a wave is on
             cameraFollow.enabled = false;
             wave1 = false;
 
             //print("time is up.");
         }
 
         else
         {
             wave1 = false;
             CancelInvoke("Wave1Attack");
             cameraFollow.enabled = true;
         }
         */
 
         /*
         if(wave1 )
         {
             wave1 = true;
             Wave1Attack();
         }
 
         if(!wave1)
         {
             wave1 = false;
             CancelInvoke("Wave1Attack");
         }
          */
     }
 
 
     public void BlockCollidersOn()
     {
         blockColliders.SetActive(true);
         followTarget.enabled = true;
     }
 
     public void BlockCollidersOff()
     {
         blockColliders.SetActive(false);
         followTarget.enabled = false;
     }
 
 
 
     public void SpawnEnemies()
       {
           int ranValue = Random.Range(spawnRateMin, spawnRateMax +1);
 
           for (int i = 0; i < ranValue; i++)
           {
               int ranSpawn = Random.Range(0, spawnPosition.Length);
               GameObject Clone = Instantiate(footPrefab, spawnPosition[ranValue].position, Quaternion.identity) as GameObject;
             //GameObject Clone
             //enemiesSpawned.Add(Clone.transform);
               enemiesSpawned.Add(Clone.transform);
           }
       }
       
 
 
   /*
     public void Wave1Attack()
     {
       
         int spawnPointIndex = Random.Range(0, spawnPosition.Length);
 
         Instantiate (footPrefab, spawnPosition[spawnPointIndex].position, spawnPosition[spawnPointIndex].rotation);
     }
     */
    }
 
 
 
 
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

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

119 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

Related Questions

How can you load next the level after you destroy the last clone c# 1 Answer

Instantiate question 0 Answers

Fitting an instantiated prefab inside a cube? 0 Answers

Passing variables from one script to all clones 1 Answer

Unity_5.6.1f1 >> Unity_5.5.0f3 - Animation problems (missing reference)... 0 Answers


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