can't damage spawned prefab
Okay so the problem i have is that if i add zombies to the scene and then start the game I can kill them fine without a problem. but when i start the game if i spawn them with this code my shoot script no longer applies damage? any ideas?
     [ClientRpc]
     void RpcSpawnZam()
     {
         Instantiate(zamby, new Vector3(80, 0, 90), Quaternion.identity);
     }
PlayerShoot Script
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class PlayerShoot : NetworkBehaviour
 {
     public PlayerWeapon weapon;
     public ZombieHealth zamhealth;
 
     [SerializeField]
     private Camera cam;
 
     [SerializeField]
     private LayerMask mask;
 
     void Start()
     {
         if (cam == null)
         {
             Debug.Log("No Cam");
             this.enabled = false;
         }
         if (zamhealth == null)
         {
             Debug.Log("No Zombie");
         }
        // heart = GameObject.Find("Heart").GetComponent <HeartTest > ();
     }
 
     void Update()
     {
         if (Input.GetButtonDown("Fire1"))
         {
             Shoot();
         }
     }
 
     [Client]
     void Shoot()
     {
         RaycastHit hit;
         if (Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, weapon.range, mask))
         {
 
             if (hit.transform.tag == "Zombie")
             {
                 CmdShot(hit.collider.name, weapon.damage);
             }
             else
             {
                 Debug.Log("Shot but Zombie not found");
             }
         }
     }
 
     [Command]
     void CmdShot(string _id, int damn)
     {
 
         if (zamhealth == null)
         {
             zamhealth = GameObject.Find(_id).GetComponent<ZombieHealth>();
             Debug.Log("shoot set to "+_id);
         }
         //Debug.Log(_id + " was hit for "+damn);
         //HeartTest.HeartDamage(damn);
         //dammage
         //  heart.HeartDamage(4);
         zamhealth.RpcZombieDamage(100);
         Debug.Log(_id+ " should be hit for 100");
 
     }
 
 }
Zombie Health Script:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class ZombieHealth : NetworkBehaviour
 {
     [SerializeField]
     private int ZombieMaxHealth = 100;
 
     [SyncVar]
     private int ZombieCurrentHealth;
 
     // Use this for initialization
     void Start () {
         ZombieCurrentHealth = ZombieMaxHealth;
 
     }
     
     // Update is called once per frame
     void Update () {
         CmdDestory();
         Debug.Log(gameObject.name + " health = " +ZombieCurrentHealth);
     }
 
     [Command]
     void CmdDestory()
     {
         if (ZombieCurrentHealth < 1)
         {
             Debug.Log("should be fucken dead");
             Destroy(gameObject);
         }
     }
 
     [ClientRpc]
     public void RpcZombieDamage(int dam)
     {
         ZombieCurrentHealth -= dam;
     }
 }
 
               Comment
              
 
               
              Does the "zamby" prefab have the correct scripts attached?
Answer by Tyronn · Feb 15, 2017 at 02:49 PM
Turns out to spawn something on the Network properly and not visually. you need to use network.spawn method
Your answer
 
 
             Follow this Question
Related Questions
Fall Damage script not working 1 Answer
How to do multiple inheritance (or workaround) with Unity? 1 Answer
Enemy wont deal damage 0 Answers
Prefab script member values not correct 0 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                