• 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 crums · Dec 29, 2010 at 11:02 AM · instancebce0020

scripting touch ups

i'm finally nearing completing my game and its just the countdownTimer which is creating problems now, i wish to have a point collecting script from the countdownTimer which then goes towards my final overall score received at the end of my game. this final score consists of adding the points received from my countdown timer and the number of boxes collected. here is my countdownTimer script:

private var startTime; private var restSeconds : int; private var roundedRestSeconds : int; private var displaySeconds : int; private var displayMinutes : int; private var Points : int;

 var countDownSeconds : int;

 function Awake() {
     startTime = Time.time;
 }

 function OnGUI () {
     //make sure that your time is based on when this script was first called
     //instead of when your game started
     var guiTime = Time.time - startTime;



     restSeconds = countDownSeconds - (guiTime);

     //display messages or whatever here -->do stuff based on your timer
     if (restSeconds == 60) {
         print ("One Minute Left");
     }
     if (restSeconds == 0) {
         print ("Time is Over");
         //do stuff here
     }

     //display the timer
     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
     displaySeconds = roundedRestSeconds % 60;
     displayMinutes = roundedRestSeconds / 60; 

     text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 
     GUI.Label (Rect (400, 25, 100, 30), text);
 }

 function Update () {
  if(Time.time <= 60) //if you make it before 60 seconds
  {
   Points = 20; //add points
  }
  if(Time.time <= 30) //if you made it before 30 seconds
  {
   Points = 10; //add points
  } 
 }

here is my box collect script:

static var Count : int = 0 ;

function OnCollisionEnter(theCollision : Collision) { if (theCollision.gameObject.name == "box"){ Destroy (theCollision.gameObject); Count ++; } }

and here is my finalScore script:

var finalScore;

function Addscore(){

 var finalScore = boxCollect.Count * countdownTimer.Points;

}

function Update () {
guiText.text = finalScore;

}

i personally can't seem to find the problem with any of these scripts, but the debug log comes up with the message

"Assets/JavaScript/finalScore.js(5,60): BCE0020: An instance of type 'countdownTimer' is required to access non static member 'Points'."

any suggestions are greatly appreciated. it seems that my finalScore script can't seem to link to the countdownTimer.Points but im not too sure as too why.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Using multiple instances of the same script 1 Answer

Build Queue Logic In Turn-based Strategy 1 Answer

Should I manually delete my custom class instances? 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