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 oomeroo1999 · Jul 10, 2019 at 11:49 AM · scripting problemgameobject

Is there something like "destroy otomatically" ? Because I don't destroy but it gets destroyed.

Hi. I'm talking about script. I define a gameobject like

 public class Server : MonoBehaviour
 {
     private GameObject go1;

I don't use anything like Destroy or DestroyImmediate. Is there something I don't know? Because I really don't understand why it gets destroyed..

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 pmerilainen · Jul 10, 2019 at 01:05 PM

Have you assigned a value to go1. By default all references are null.

Comment
Add comment · Show 15 · 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
avatar image oomeroo1999 · Jul 10, 2019 at 01:14 PM 0
Share

Of course I did. I'm making a multiplayer game. The problem is: I can reach it when first player joins in but I can't reach it when second player joins in.

Here is some parts of my server script:

https://www.dosyaupload.com/j4vZ

avatar image pmerilainen oomeroo1999 · Jul 10, 2019 at 01:23 PM 0
Share

Browsed through your code snipped. Saw nothing wrong (except the Transform tr; can be local in the OnInco$$anonymous$$gData callback). It seems you do not validate the data at all, so if your data does not have delimiter character | or second entry is not numeric value, the script will not function correctly. So first you should check the data is correct for the second 'player spawn' message (you can log it for instance)

avatar image oomeroo1999 pmerilainen · Jul 10, 2019 at 04:05 PM 0
Share

No. There is nothing wrong with delimiter or numeric value.

Let me explain more.

I made the multiplayer game. Two player gets connected. They choose the hero they want (from 4 different heros). And game starts. They can move and they can see each other moving. So there was no problem.

But later, I've learned that I should keep the transforms of the players in Server. Otherwise my game could have been hacked. So I decided to keep the transforms in server. And when a player wants to move, the transform info at the server will change. I will send this changed value to the client.

I think this would be enough for security. But somehow I can't avoid transform from being destroyed. Someone adviced me to use Vector3 ins$$anonymous$$d of Transform. I will try it.

Show more comments
avatar image akaBase oomeroo1999 · Jul 10, 2019 at 10:01 PM 0
Share

Can you add code here, expecting people to download files to help is asking too much! and will turn people like myself away.

avatar image oomeroo1999 akaBase · Jul 11, 2019 at 12:44 PM 0
Share

Here is the code I've uploaded:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class SS : $$anonymous$$onoBehaviour
 {
     private List<Transform> transforms;
     Transform tr;
 
     public void Init()
     {
         DontDestroyOnLoad(gameObject);
         transforms = new List<Transform>();
     }
 
     private void OnInco$$anonymous$$gData(ServerClient c, string data)
     {
         string[] aData = data.Split('|');
 
         switch (aData[0])
         {
             case "CNU$$anonymous$$":
                 c.number = int.Parse(aData[1]);
 
                 tr = new GameObject().transform;
 
                 if (c.number % 2 == 1)
                     tr.SetPositionAndRotation(new Vector3(0, 0, -7), Quaternion.identity);
                 else
                     tr.SetPositionAndRotation(new Vector3(0, 0, 7), Quaternion.identity);
                 transforms.Add(tr);
 
                 Debug.Log("SAYI: " + transforms.Count);
                 if (c.number == 2)
                     Debug.Log(transforms[1].position.x);
 
                 Debug.Log(transforms[0].position.x);
                 break;
 
             default:
                 break;
         }
     }
 }

Actually, first thing I need to learn is what should I keep at server. I mean, should I keep whole gameobject or transform or position and rotation ? Which is better ?

Show more comments

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

225 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 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

GameObject is already being activated or desactivated 2 Answers

How to make an object invisible before it is triggered to show? 2 Answers

Creating a GameObject variable without instantiating it? 1 Answer

Rotate GameObject When Mouse/Player is Within Certain Distance From it 1 Answer

Making a defibrillator patch for a simulation 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