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 TylerNW3994 · Jan 04, 2017 at 05:39 PM · camerabeginner

Code being run only when object is selected in editor.

Hello all,

I'm trying to have a simply level progression system where after the player defeats the enemy, they move up a level. I tried making it so one object references a variable that doesn't go away due to DontDestroyOnLoad(). However, it seems like this code is only run when I have the main camera selected in the editor. I don't think its a code issue because I don't have anything to do with the editor in my code, but to be honest this doesn't make any sense to me as to why this is a thing.

What I have attached to the camera:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Loader : MonoBehaviour {
 
     public GameObject gameMananger;
     private BoardManager boardManager;
     public BoardManager BM;
     void Awake() {
         if (GameManager.instance == null)
             Instantiate(gameMananger);
         else {
             boardManager = gameMananger.GetComponent<BoardManager>();
             boardManager.SetupScene();
         }
         BM = gameMananger.GetComponent<BoardManager>();
         //This usually stays at 1 unless I click on the camera
         //When I have the camera selected it displays both the Log and increments BM.Level
         //When I either have nothing selected or anything but the camera selected it only displays the Log but resets back to level 1
         Debug.Log("Adding to level");
         BM.Level++;
     }
 }


And just for reference, here is the boardManager that contains "Level":

 using System.Collections;
 using System;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BoardManager : MonoBehaviour {
     public static BoardManager instance = null;
     [Serializable]
     public class Count {
         public int minimum;
         public int maximum;
 
         public Count(int min, int max) {
             minimum = min;
             maximum = max;
         }
     }
 
     public int columns = 2;
     public int rows = 2;
     private int level = 1;
     public int Level{
         get {
             return level;
         }
         set {
             level = value;
         }
     }
 
     public GameObject boardTile;
     public GameObject[] visitedTiles;
 
     private Transform boardHolder;
     private List<Vector3> gridPositions = new List<Vector3>();
     public GameManager gameManager;
 
     public void InitializeList() {
         gridPositions.Clear();
         for(int x = 1; x < columns-1; x++) {
             for(int y = 1; y < rows-1; y++) {
                 gridPositions.Add(new Vector3(x, y, 0f));
                 
             }
         }
     }
 
     public void BoardSetup() {
         gameManager = gameObject.GetComponent<GameManager>();
         Debug.Log("Level " +level);
         boardHolder = new GameObject("Board").transform;
         int count = 0;
         for (int x = -1; x < columns; x++) {
             for(int y=-1; y < rows; y++) {
                 GameObject instance = Instantiate(boardTile, new Vector3(x, y, 0f), Quaternion.identity) as GameObject;
                 instance.transform.SetParent(boardHolder);
                 instance.name = (++count).ToString();
                 //If at current level
                 if (level == count)
                     instance.GetComponent<SpriteRenderer>().color = new Color(0f, 1f, 0f, 1f);
                 //If at previous level
                 else if (level > count)
                     instance.GetComponent<SpriteRenderer>().color = new Color(1f, 1f, 0f, 1f);
 
             }
         }
     }
 
     public void SetupScene() {
         BoardSetup();
 
         InitializeList();
     }
 }
 


If I need to provide any other information, please let me know because I cannot think of a reason as to why this is happening. I don't think any of my code has anything to do with me having the camera selected.

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

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

Hiding model for local player 1 Answer

How do I make a 3d person camera that changes with keyboard based input 1 Answer

Camera zoom out relative to player's speed 1 Answer

Camera for 3D game Help 1 Answer

VR - setting up cockpit to drift slightly 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