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 ImDose · Feb 23, 2013 at 12:58 AM · invokenottoexpressionpossible

It is not possible to invoke an expression of type 'SpriteManager[]'.

I'm trying to code a 2d platformer. I keep getting this error, when I try to change the [] to () it tells me unexpected token. I try with semicolen, and without. I'm not sure what the issue is, so here is the script.

 public var f_speed : float = 5.0;
 public var loopSprites : SpriteManager[];
 private var in_direction : int;
 
 
 function Start () : void {
     in_direction = 1;
 //initialization Sprite Manager
     for (var i : int = 0; i<loopSprites.length; i++) {
         loopSprites[i].init();
 }
 //Update main camera to the character position
 Camera.main.transform.position = new Vector3 (transform.position.x, transform.position.y, Camera.main.transform.position.z);
 }
 
 
 
 public function Update () : void {
     if (Input.GetButton("Horizontal")) {
         //walking
         in_direction = Input.GetAxis("Horizontal") < 0 ? -1: 1;
         rigidbody.velocity = new Vector3((in_direction*f_speed),
     rigidbody.velocity.y, 0);
         //reset stay animation frame back to the first frame
         loopSprites(0).resetFrame();
         //update walking animation while the character is walking
         loopSprites(1).updateAnimation(in_direction, renderer.material);
         } else {
         //stay
         //reset walking animation frame back to the first frame
         loopSprites(1).resetFrame();
         //update stay animation while the character is not walking
         loopSprites(0).updateAnimation(in_direction, renderer.material);
         }
     }
     
 public function LateUpdate() : void {
 //update main camera
     Camera.main.transform.position = new Vector3(transform.position.x, transform.position.y, Camera.main.transform.position.z);
 }    
     class SpriteManager {
         public var spriteTexture : Texture2D; //set texture use for a loop animation such as walking, stay, etc.
         public var in_framePerSec : int; //get frame per sec to calculate time
         public var in_gridx : int; //get max number of horizontal images
         public var in_gridy : int; //get max number oif vertical images
         private var f_timePercent : float;
         private var f_nextTime : float; //update time byte using frame persecond
         private var f_gridx : float;
         private var f_gridy : float;        
         private var in_curFrame : int;
         
         public function init () : void {
             f_timePercent = 1.0/in_framePerSec;
             f_nextTime = f_timePercent; //update time by using frame
             f_gridx = 1.0/in_gridx;
             f_gridy = 1.0/in_gridy;
             in_curFrame = 1;
         }
         
         public function updateAnimation (_direction : int, _material : Material) : void {
         //update material
         _material.mainTexture = spriteTexture;
         //update frame by time
         if (Time.time>f_nextTime) {
             f_nextTime = Time.time + f_timePercent;
             in_curFrame++;
             if (in_curFrame>in_framePerSec) {
                 in_curFrame = 1;
             }
         }
         _material.mainTextureScale - new Vector2 (_direction * f_gridx, f_gridx);
         var in_col : int = 0;
         if (in_gridy> 1) {
             //if there is more than one grid on the y-axis update the texture
         in_col= Mathf.Ceil(in_curFrame/in_gridx);
         }
             if(_direction == 1) { //right
             _material.mainTextureOffset = new Vector2(((in_curFrame%in_gridx)) * f_gridx, in_col*f_gridy);
                 }
             }
             
             public function resetFrame () :void {
                 in_curFrame = 1;
                 }
             }
         
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Feb 23, 2013 at 01:09 AM

This is totally wrong:

 loopSprites(0).resetFrame();

The normal brackets () are used to invoke a method but loopSprites is an array. You have to use the index brackets []:

 loopSprites[0].resetFrame();
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

10 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

Related Questions

Unity Iphone "It is not possible to invoke an expression of type 'Object'. 1 Answer

How to make camera not rotate with player, only move 1 Answer

Invoke doesn't work when with certain second 0 Answers

not able to see my character 0 Answers

anonymous functions with JavaScript? 2 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