Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Maestro Beginner · Sep 28, 2014 at 04:35 AM · clonepointssend

send SCORE from OBJECT(clone) to other file

Hi guys. My experience is very small. And my english bad. And Google in 10 hours could not help me.

I have 3 script

  1. cameraController

  2. bg

  3. bubbleMove

cameraController contains a system of points. bg creates object clones from prefab, prefab have script bubbleMove, and when the condition inside the script right, points in cameraController must be plus, but unity3d say me: "NullReferenceException: Object reference not set to an instance of an object bubbleMove.Update () (at Assets/bubbleMove.cs:18)".

What am I doing wrong? How to deal? I'm attach the screens and scripts.

cameraController

 using UnityEngine;
 using System.Collections;
 
 public class cameraController : MonoBehaviour {
     public bubbleMove bubbleMove;
     public Vector3 mousPos;
     public Vector3 mousePos;
     public Vector3 worldPos;
     public int width;
     public int height;
     public Vector2 screenSize;
     public Vector2 worldScreenSize;
     public int score = 0;
     public int scorePlus = 1;
 
     // Use this for initialization
     void Start () {
         screenSize = new Vector2(width, height);
         worldScreenSize = Camera.main.ScreenToWorldPoint(screenSize);
         score = 0;
         scorePlus = 1;
         width = Screen.width;
         height = Screen.height;
     }
     
     // Update is called once per frame
     void Update () {
         print("scoreFrom cameraController="+score);
     }
     
 }


bg

 using UnityEngine;
 using System.Collections;
 
 public class bg : MonoBehaviour {
     public cameraController cameraController;
     public GameObject RandB;
     public int bubbleCount;
     float d;
     private int i;
     private Vector2 mapSize;
     
 
     // Use this for initialization
     void Start () {
 
         
     }
     
     // Update is called once per frame
     void Update () {
         mapSize = new Vector2(cameraController.worldScreenSize.x, cameraController.worldScreenSize.y);
         for (int i = 0; d + 1 < Time.time && i < bubbleCount; i++ )
         {
             
             GameObject bubbleClone1;
             bubbleClone1 = Instantiate(RandB, new Vector2(Random.Range(-mapSize.x, mapSize.x),
                                                          Random.Range(-mapSize.y, mapSize.y)), RandB.transform.rotation) as GameObject;
             GameObject bubbleClone2;
             bubbleClone2 = Instantiate(RandB, new Vector2(Random.Range(-mapSize.x, mapSize.x),
                                                           Random.Range(-mapSize.y, mapSize.y)), RandB.transform.rotation) as GameObject;
             GameObject bubbleClone3;
             bubbleClone3 = Instantiate(RandB, new Vector2(Random.Range(-mapSize.x, mapSize.x),
                                                           Random.Range(-mapSize.y, mapSize.y)), RandB.transform.rotation) as GameObject;
             GameObject bubbleClone4;
             bubbleClone4 = Instantiate(RandB, new Vector2(Random.Range(-mapSize.x, mapSize.x),
                                                           Random.Range(-mapSize.y, mapSize.y)), RandB.transform.rotation) as GameObject;
 
             d = Time.time;
             
         }
     }
 }
 

bubbleMove

 using UnityEngine;
 using System.Collections;
 
 public class bubbleMove : MonoBehaviour {
     public cameraController cameraController;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
 
         transform.Translate (-Vector3.up * 0.1001f);
 
         if(transform.position.y < 0)
         {
             cameraController.score = cameraController.score + cameraController.scorePlus;
             print("score from bubbleMove="+cameraController.score);
             Destroy (gameObject);
         }
 
 
 
     }
 }
 



alt text

alt text

myunity.png (208.1 kB)
errorunity.png (200.7 kB)
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by mattyman174 · Sep 28, 2014 at 05:45 AM

 public cameraController cameraController;

In your bubbleMove script, your cameraController is never given an initial value.

You should initialize it within your Start() method.

Comment
Add comment · Show 1 · 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 Maestro Beginner · Sep 28, 2014 at 10:43 PM 0
Share

Hi guys, i can't did it right. I need that: If CLONE have y<0, cameraController from $$anonymous$$ain Camera doing score+1. cameraController from $$anonymous$$ain Camera show in console all score.

Please show me, how i can do it...

avatar image
0

Answer by xuanyusong · Sep 28, 2014 at 06:34 AM

public cameraController cameraController; cameraController must be rename

public class bubbleMove : MonoBehaviour { public cameraController cameraController; // Use this for initialization void Start () { cameraController = gameObject.AddComponent(); }

 // Update is called once per frame
 void Update () {
 
     transform.Translate (-Vector3.up * 0.1001f);
 
     if(transform.position.y < 0)
     {
         cameraController.score = cameraController.score + cameraController.scorePlus;
         print("score from bubbleMove="+cameraController.score);
         Destroy (gameObject);
     }
 
 
 
 }

}

Comment
Add comment · Show 1 · 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 Maestro Beginner · Sep 28, 2014 at 10:43 PM 0
Share

Hi guys, i can't did it right. I need that: If CLONE have y<0, cameraController from $$anonymous$$ain Camera doing score+1. cameraController from $$anonymous$$ain Camera show in console all score.

Please show me, how i can do it...

avatar image
0

Answer by Maestro Beginner · Sep 29, 2014 at 12:59 AM

SOLVE

         nowScorePlus = GameObject.Find ("Main Camera").GetComponent<cameraController> ().scorePlus;
         nowScore = GameObject.Find ("Main Camera").GetComponent<cameraController> ().score;
         nowScore = nowScore + nowScorePlus;
         GameObject.Find("Main Camera").GetComponent<cameraController>().score = nowScore;

add this Strings in bubbleMove file. I'm so cool!!)) this working!!! 4 strings, and i'm solve this 15hours

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I assign a script to a clone through another script? 1 Answer

How to stop all StopAllCoroutines(); from another script 1 Answer

How to make camera follow to clone player not first production ? 0 Answers

OnControllerColliderHit counting twice towards score 0 Answers

Scoresystem wont function correctly 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