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 Oobi23 · Apr 01, 2015 at 06:01 AM · newbietap

Creating a game similar to ant smasher? Error

Hi there, This is what I have done so far.

It does not seem to be working.. any advice?

1)Create a sphere and make it as a prefab.Rename it as enemy.

2)Create an Empty GameObject and rename it as LevelHandler.

3)Create an Empty GameObject and rename it as ScoreHandler.

4)create a script for enemy and add the following code. Drag the script to enemy and apply.

 #pragma strict
 var speed:float;
 var effect:GameObject;
 var scorehandler:GameObject;
 function Awake () {
 scorehandler=GameObject.Find("ScoreHandler");
 var temp:float=LevelHandler.level;
 Debug.Log(temp);
 speed=temp/10;
 }
 
 function Update () {
 transform.Translate(0,0,speed*Time.deltaTime);
 }
 
 function OnMouseDown()
 {
 scorehandler.gameObject.SendMessage("AddScore");
 Instantiate(effect,transform.position,transform.rotation);
 Destroy(gameObject);
 }
 

5)create a script for levelhandler add the following code. Drag the script to LevelHandler in hierarchy

 #pragma strict
 
 public static var level:int=1;
 
 var enemy:GameObject;
 function Start () {
 level=1;
 InvokeRepeating("Bug",1.0,1.0);
 }
 
 function Update () {
 
 }
 
 
 function Bug()
 {
      var pos=Random.Range(-1.0,1.0);
      
      Instantiate(enemy,Vector3(pos,0,1),transform.rotation);
 }
 
 function StopBug()
 {
   CancelInvoke("Bug");
   var obj=GameObject.FindGameObjectsWithTag("Finish");
   for(var i=0;i<obj.length;i++)
   {
      Destroy(obj[i].gameObject);
   }
   
 }
 
 
 function IncreaseLevel()
 {
   level+=1;
   
   yield WaitForSeconds(2);
   InvokeRepeating("Bug",1.0,1.0);
    scorehandler.gameObject.BroadcastMessage("LevelNo",level);
 
 }
 

6)create a script (C#)for scorehandler add the following code. Drag the script to ScoreHandler in hierarchy

 using UnityEngine;
 using System.Collections;
 
 public class ScoreHandler : MonoBehaviour {
  public int[] tlevel;
  public int level;
  public int score;
  public int bug=0;
  private GameObject LevelHandler;
  // Use this for initialization
  void Start () {
   LevelHandler = GameObject.Find ("LevelHandler");
   level = 1;
  }
  
  // Update is called once per frame
  void Update () {
  
  }
   void AddScore()
  {
 
 
   for (int i=0; i<tlevel.Length; i++) {
       if (level == tlevel [i]+1) {
     if (bug >= 10) {
         LevelHandler.gameObject.SendMessage ("StopBug");
    
         LevelHandler.gameObject.SendMessage ("IncreaseLevel");
         bug = 0;
     }
       }
     }
   
   bug += 1;
   score += 10;
  }
  void OnGUI()
  {
   GUI.Label (new Rect (Screen.width - 100, 25, 100, 100), "Score " + score);
  }
 
  void LevelNo(int lev)
  {
   level = lev;
  }
 
 }

7)Place enemy prefab to enemy in hierarchy for LevelHandler script

8)Change tlevel size to 10 in scorehandler script in inspector and give values from 0,1,2,,,...to 9.

I keep getting error "unknown identifier: scorehandler" from the levelhandler script.

What am i doing wrong?.. any help is appreciated.

Comment
Add comment · Show 2
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 DoTA_KAMIKADzE · Apr 01, 2015 at 06:10 AM 0
Share

From what I can see you're using scorehandler reference in line 41 of your "LevelHandler" script - but it doesn't contain a reference to scorehandler instance. Either find it like you do in your ScoreHandler finding LevelHandler, or provide it in Inspector like you do with your enemy prefab.

avatar image NoseKills · Apr 01, 2015 at 06:13 AM 0
Share

You don't have a variable scorehandler in your LevelHandler class. You would have to use GameObject.Find("ScoreHandler").GetComponent() to get a reference to scorehandler, but since you are mixing javascript and c#, it won't be as simple as that. Can't remember right away how it should be done in this case.

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

21 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

Related Questions

first tutorial to use? 1 Answer

My IOS touch input is not working 0 Answers

Why my object not disappear? 1 Answer

How do I make a level-to-level loading screen with bar? 1 Answer

Addforce.forward on a sphere object 1 Answer


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