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 Tyronn · Feb 10, 2017 at 07:01 PM · c#prefabserverdamagehealth

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
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 Nomenokes · Feb 11, 2017 at 07:09 PM 0
Share

Does the "zamby" prefab have the correct scripts attached?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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

Comment
Add comment · Share
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

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

possible to ping project asset on log click ? 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