Quantcast
Channel: Questions in topic: "clone"
Viewing all articles
Browse latest Browse all 508

Missing Component in a Clone

$
0
0
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(); } if(footExplosionSound == null) { footExplosionSound = GetComponent(); } footExplosionSound = GetComponent(); if (anim == null) { anim = GetComponent(); } if (playerController == null) { playerController = GetComponent(); } if (enemySight == null) { enemySight = GetComponent(); } if (gameManager == null) { gameManager = GetComponent(); } if (characterStats == null) { characterStats = GetComponent(); } } // 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 enemiesSpawned = new List(); 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(); } if(blockColliders ==null) { blockColliders = GetComponent(); } if(followTarget == null) { followTarget = GetComponent(); } } // 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); } */ }

Viewing all articles
Browse latest Browse all 508

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>