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 lecanardbleu · Apr 17, 2012 at 07:07 PM · variablesspeedmotor

Reading Other Scripts stats

Hi. Im trying to make it so that when you increase the Spd variable it changes the max movement speed and im trying to get the variable Spd from my Script Stats. i made sure its spelled right but its not working. heres my coed class CharacterMotorMovement {

 // The maximum horizontal speed when moving
 @System.NonSerialized
 **static var Spd : float = Stats.Spd;**
 @System.NonSerialized
 var maxForwardSpeed : float = 1;
 @System.NonSerialized
 var maxSidewaysSpeed : float = 1;
 @System.NonSerialized
 var maxBackwardsSpeed : float = 1;
 
 // Curve for multiplying speed based on slope (negative = downwards)
 var slopeSpeedMultiplier : AnimationCurve = AnimationCurve(Keyframe(-90, 1), Keyframe(0, 1), Keyframe(90, 0));
 
 // How fast does the character change speeds?  Higher is faster.
 @System.NonSerialized
 var maxGroundAcceleration : float = 30.0;
 @System.NonSerialized
 var maxAirAcceleration : float = 20.0;

 // The gravity for the character
 var gravity : float = 10.0;
 var maxFallSpeed : float = 20.0;
 
 // For the next variables, @System.NonSerialized tells Unity to not serialize the variable or show it in the inspector view.
 // Very handy for organization!

 // The last collision flags returned from controller.Move
 @System.NonSerialized
 var collisionFlags : CollisionFlags; 

 // We will keep track of the character's current velocity,
 @System.NonSerialized
 var velocity : Vector3;
 
 // This keeps track of our current velocity while we're not grounded
 @System.NonSerialized
 var frameVelocity : Vector3 = Vector3.zero;
 
 @System.NonSerialized
 var hitPoint : Vector3 = Vector3.zero;
 
 @System.NonSerialized
 var lastHitPoint : Vector3 = Vector3(Mathf.Infinity, 0, 0);

}

it gives the error : Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.js(27,34): BCE0005: Unknown identifier: 'Stats'.

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 Lttldude · Apr 17, 2012 at 09:54 PM

Disclaimer: I don't know c# that well.

I think you need to get and define the script before you start accessing it's variables. Is it on the same object, if not then replace gameObject with whichever object it is on.

Should look something like this:

 void Start() {
 Stats other;
 other = gameObject.GetComponent("Stats") as Stats;
 }
 
 void Update() {
 spd = Stats.spd;
 }

Tell me if that works or not. Good Luck.

  • Josh

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
avatar image
0

Answer by T27M · Apr 17, 2012 at 11:39 PM

     void Start() { 
 Stats statsScript;
 statsScript = GetComponent<Stats>();

}

 void Update () {
 spd = Stats.spd;

}

or

 public Stats statsScript;

 void Start () {
 statsScript = GetComponent("Stats") as Stats;

}

 void Update () {
 spd = Stats.spd;

}

http://unity3d.com/support/documentation/ScriptReference/Component.GetComponent.html

Looked at a few in my own scripts aswell, this should work.

Comment
Add comment · Show 3 · 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 lecanardbleu · Apr 17, 2012 at 11:40 PM 0
Share

Sorry. its in java so i dont know how i would put that in.

avatar image syclamoth · Apr 18, 2012 at 12:01 AM 0
Share

What are you using java for? Unity doesn't even compile java.

avatar image Lttldude · Apr 18, 2012 at 03:13 AM 0
Share

he meant unityscript I believe.

avatar image
0

Answer by Lttldude · Apr 17, 2012 at 11:49 PM

Here is the javascript one:

 var statsScript : Stats;
 
 Start() {
 statsScript = gameObject.GetComponent("Stats");
 }
  
 Update() {
 spd = Stats.spd;
 }
Comment
Add comment · Show 4 · 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 lecanardbleu · Apr 18, 2012 at 01:44 AM 0
Share

now it says. i made sure i spelled Stats right. Capital S and then lowercase tats. i dont know why but its not recognizing any scripts. ive tryed having other scripts read Spd and its fine but This one isnt. Btw its the FPS charaqcter motor script. i just modified it. hopefully this helps.

Assets/Standard Assets/Character Controllers/Sources/Scripts/Character$$anonymous$$otor.js(4,19): BCE0018: The name 'Stats' does not denote a valid type ('not found').

avatar image Lttldude · Apr 18, 2012 at 03:13 AM 0
Share

can you post the line in error?

avatar image lecanardbleu · Apr 19, 2012 at 11:09 PM 0
Share

var statsScript : Stats;

its the first part that you gave me.

avatar image Lttldude · Apr 20, 2012 at 04:17 PM 0
Share

"Stats" has to be the name of your script. example: The character motor script would be reference as Character$$anonymous$$otor. Just make sure you have a script with that name.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Altering Character Motor max speeds from script 0 Answers

How to change scripts to include Waves of Enemy? 0 Answers

Using pre-made script to pause Mouselook X axis not pausing 1 Answer

My Instantiate script isn't working. Why? 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