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 /
This question was closed Mar 25, 2014 at 08:43 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by BawsAnimations · Mar 23, 2013 at 04:11 PM · camerajavascriptfunctioncallsprint

Calling Functions from another Script

Okay, so situation is, I have a charactermotor script(default unity package). I also have a Camera bobbing script.

For some reason this wont work! I want to say basically, if the character speed is greater than 2, show a debug. So I am calling a function such as this :

 var bobscript : CamBob;
 
 function Update () {
     
     if(movement.maxForwardSpeed > 2.0) {
     
     bobscript.DoSomething();
     }
     
     
     
     }

and then, my other script, (cambob script) :

 function DoSomething () 
  {
  Debug.Log("DoSomething Active");
  }
 
 // this is just the function im trying to call, not the entire script.



















I KEEP GETTING THIS ERROR : Assets/Standard Assets/Character Controllers/Sources/Scripts/CharacterMotor.js(334,17): BCE0018: The name 'CamBob' does not denote a valid type ('not found').

Comment
Add comment · Show 1
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 whebert · Mar 23, 2013 at 04:18 PM 0
Share

Is the name of your Camera bobbing script exactly "CamBob.js"? If your script file name is lowercase "cambob.js", than you need to match the case exactly.

3 Replies

  • Sort: 
avatar image
0
Best Answer

Answer by ransomink · Mar 23, 2014 at 06:37 PM

  1. You are referencing the script properly, but inside the inspector, you must add/drag the GameObject (using the CamBob script) into the bobscript (empty slot).

  2. Make sure your spelling and casing is correct for your script. As whebert mentioned above, you must match the case exactly, so it's either: "CamBob.js" or "cambob.js" (basically whatever you named it).

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
-1

Answer by Fappp · Mar 24, 2014 at 09:38 PM

 var bobscriptGo : GameObject;
  
 function Update () {
  
     if(movement.maxForwardSpeed > 2.0) {
  
     bobscript.SendMessage("DoSomething", 1);;
     }
  
  
  
     }

and then in bobscript:

 function DoSomething (sentVar : int) 
  {
  Debug.Log("DoSomething Active" + sentVar);
  }
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 fafase · Mar 25, 2014 at 07:02 AM 0
Share

This is way slower than GetComponent. You should consider this way when it makes GetComponent complicated, else avoid.

avatar image
0

Answer by ransomink · Mar 25, 2014 at 06:42 AM

Cambob script

 public function DoSomething ()
 {
     Debug.Log ( "You should be doing something...");
 }

Script that calls the function

 // this variable will show up in the inspector
 // place the GameObject that has the Cambob script attached to it inside the variables' field
 public var bobScript : Cambob;
 
 function Update ()
 {
     bobScript.DoSomething ();
 }

You can also reference the Cambob script through code so you don't have to use the editor, but this method is slower.

 // I made it private because there is no need to use/change it inside of the editor
 // (unless you want to check if the correct GameObject appears when executed).
 private var bobScript : Cambob;
 
 function Awake ()
 {
     bobScript = GameObject.Find ( "The GameObject Name" ).GetComponent ( Cambob );
 }
 
 function Update ()
 {
     bobScript.DoSomething ();
 }
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

Follow this Question

Answers Answers and Comments

13 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

Related Questions

Script not function if mouse is on object 1 Answer

How to access variable from another function? 2 Answers

Destroy object question! 3 Answers

BCE0044: expecting (, found 'OnGUI'. 1 Answer

Pan Orthographic Camera 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