Quantcast
Channel: Questions in topic: "namespace"
Viewing all articles
Browse latest Browse all 398

NameSpace Error EnemyHealth Cant Access Other Script.

$
0
0
Hey guys I'm fairly new to unity and was working on a project for school and came across this error The Type or namespace name 'EnemyHealth' could not be found(are you missing a using directive or an assembly reference?) All I'm trying to do is call the take damage function in my enemy health code. Here is my code: using UnityEngine; using System.Collections; public class PLayerShooting : MonoBehaviour { public ParticleSystem muzzleFlash; Animator anim; public GameObject impactPrefab; public float hitForce = 1000; int amount = 1; bool shooting = false; GameObject target; // Use this for initialization void Start () { anim = GetComponentInChildren(); } // Update is called once per frame void Update () { if(Input.GetButtonDown("Fire1")) { muzzleFlash.Play(); anim.SetTrigger("Fire"); Shooting(); } } void Shooting() { RaycastHit hit; if (Physics.Raycast(transform.position, transform.forward, out hit, 50f)) { EnemyHealth enemyHealth = hit.collider.GetComponent(); if (enemyHealth != null) { enemyHealth.TakeDamage(amount); } Instantiate(impactPrefab, hit.point, transform.rotation); impactPrefab.transform.position = hit.point; impactPrefab.GetComponentInChildren().Play(); } } }

Viewing all articles
Browse latest Browse all 398


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