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 bony5 · Jun 26, 2016 at 06:00 AM · c#unity 5networkingphoton

What's wrong with my script ?

Hello bros.

This script is intended to produce amount of (food) objects for the players over the network. What should happen is that when a player eats one food, another food object gets created in another random place. Somehow it doesn't do that.

Here's the script.

public class FoodManager : Photon.MonoBehaviour {

 [SerializeField] GameObject smallCirclePrefab;
 [SerializeField] float widthOfBoard = 100;
 [SerializeField] float heightOfBoard = 100;
 [SerializeField] int amtOfSmallCircle = 100;
 [SerializeField] int sizeOfCircle = 5;


 // Use this for initialization
 void Start()
 {
    if(PhotonNetwork.isMasterClient)
    produceSmallCircle(amtOfSmallCircle);
 }

 // Update is called once per frame
 void Update()
 {

 }
 void produceSmallCircle(int n)
 {
     Vector2 position;
     GameObject circle;
     float positionX, positionY;
     int ratioOfSize = 5;
     for (int i = 0; i < n; i++)
     {
         positionX = Random.Range(-widthOfBoard / 2, widthOfBoard / 2);
         positionY = Random.Range(-heightOfBoard / 2, heightOfBoard / 2);
         position = new Vector3(positionX, positionY,0);


         circle = PhotonNetwork.InstantiateSceneObject(smallCirclePrefab.name, position, transform.rotation, 0,null) as GameObject;

         circle.transform.localScale = new Vector3((float)sizeOfCircle / ratioOfSize, (float)sizeOfCircle / ratioOfSize, (float)sizeOfCircle / ratioOfSize);
     }
 }

}

and here's the other script

using UnityEngine; using System.Collections;

public class FoodCollision : Photon.MonoBehaviour {

 public static float amtOfIncreaseSpeed = 1f;
 public static float amtOfIncreaseHealth = 1f;
 public static float ratioOfSpeed = 150.0f;
 public static float increaseSize = 0.001f;

 PhotonView photonView;
 BoxCollider2D boxCollider;
 SpriteRenderer sp;

 void Awake()
 {
     photonView = PhotonView.Get(this);
     boxCollider = GetComponent<BoxCollider2D>();
     sp = GetComponent<SpriteRenderer>();
 }

 // Use this for initialization
 void Start()
 {

 }

 // Update is called once per frame
 void Update()
 {

 }

 public void DestroyGO()
 {
     
     photonView.ownerId = PhotonNetwork.player.ID;
     boxCollider.enabled = false;
     sp.enabled = false;
     photonView.RPC("DestroyRPC", PhotonTargets.MasterClient);
    
 }

 [PunRPC]
 void DestroyRPC()
 {

     PhotonNetwork.Destroy(gameObject);
 }

}

Comment
Add comment · Show 4
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 tanoshimi · Jun 26, 2016 at 09:31 PM 0
Share

And what part of that script is means to be detecting when the player has eaten the food and creating a new one?

avatar image bony5 tanoshimi · Jun 26, 2016 at 09:50 PM 0
Share

it was in another script, sorry about that, i edited the post.

avatar image Bunny83 · Jun 26, 2016 at 11:35 PM 0
Share

Questions like "What's wrong with my script" clearly belongs to the help room and not the default space as this is a pure debugging question.

I moved the question to the help room.

avatar image bony5 Bunny83 · Jun 28, 2016 at 10:41 AM 0
Share

Thanks for moving, and sorry about that.

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Photon Networking - How to move all players from game scene to current room scene? 0 Answers

Day/Night cycle turns black at night and how to Serialize it rightly? 0 Answers

How to choose different teams one by one 1 Answer

unity NetworkingLobbyManager problem 0 Answers

UNET Clients Laggy 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