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 /
avatar image
0
Question by GonTar_X · May 11, 2019 at 08:01 PM · networkingnetwork

Networking: multiple childs issue

basicly, we have 2 turrets on our game, wich are child of a main game object Who is the main body that holds there 2+ turrets.

problem is, we have both turrets movement sync perfectly and all

but we have an issue with unity mixing the turrets fire, we usually copy/paste the component on the main body "parent" gameObj for each turret on said parent obj.

This leads to some weird behaviour, Unity only fires projectiles from the first turret, all our copies (of this script as a component) below the first one, are spawning their proyectiles on the first turret's child.

Somehow we realize unity reads components from top to bottom on the inspector, and it thinks the first turret is the only existing one, cause all copies of this script only fire from the first turret position/child for some reason.

Any clue/help advice on this topic? we kind of new to unity networking.
-And we stuck with Unet on Unity 2018.2.14f1 build cause we heard latest versions of Unity Removed Unet and are awaiting for a new kind of networking meme "Maybe to be introduced next year" / "fixed-implemented properly 2021"

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.Networking;
 
 public class Fire1 : NetworkBehaviour {
     
     
     public Vector3 bulletoffset = new Vector3(0, 0.2f, 0);
     public KeyCode key;
     public GameObject bulletprefab;
     public float firedelay = 10f;
     public float lifespam = 2.5f;
     public AudioClip ready;
     public float soundvalue = 0.2f;
     float cooldown = 0;
     public int speed = 6;
     public Rigidbody2D rb2d;
     int speedy;
     public GameObject turretobj;
     
     
     void Start(){
         Debug.Log(turretobj.transform.position);
     }
     
     // Update is called once per frame
     void FixedUpdate(){
         
         if (!isLocalPlayer) return;
         
         float vely = (rb2d.transform.right.sqrMagnitude);
         int vel = (int)vely;
         speedy = vel;
         
         if ( cooldown > 0) cooldown -= Time.deltaTime;
         
         if (Input.GetKey(key) && (cooldown <= 0)) Fire();
         
     }
     
     void Fire (){
         cooldown = firedelay;
         CmdFire(TestClient.cid);
     }
     
     [Command]
     void CmdFire (int cid){
         Vector3 offset = turretobj.transform.rotation * bulletoffset;
         Vector3 pos = turretobj.transform.position + offset;
         Vector3 rot = turretobj.transform.rotation.eulerAngles;
         FireInstance (pos, rot, cid);
         RpcFire (pos, rot, cid);
     }
     
     [ClientRpc]
     void RpcFire (Vector3 pos, Vector3 rot, int cid){
         FireInstance (pos, rot, cid);
     }
     
     void FireInstance (Vector3 pos, Vector3 rot, int cid){
         GameObject bullet = Instantiate(bulletprefab) as GameObject;
         bullet.transform.position = pos;
         bullet.transform.eulerAngles = rot;
         bullet.GetComponent<Rigidbody2D>().velocity = bullet.transform.right * (speed + speedy);
         bullet.GetComponent<Projectile>().damage.clientid = cid;
         AudioSource.PlayClipAtPoint(ready, transform.position, soundvalue);
         Destroy(bullet, lifespam);
     }
     
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GonTar_X · May 12, 2019 at 03:35 AM

anyone? we thought of adding IDs to every turret throught the script and did so, but no luck whatsoever

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

179 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 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 to Sync a sprite change to other clients? 0 Answers

Can I add a network prefab at runtime? 1 Answer

NetworkManager.OnServerDisconnect not being called 2 Answers

Network Lobby Manager Spawn Selected Prefab for Client 0 Answers

Network call Method from Instants of Prefab 2 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