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 Patrick 1 · Jul 25, 2010 at 05:52 PM · errorsyntax-erroroverloadbce0017

The best overload for the method 'UnityEngine.Object.FindObjectOfType(System.Type)' is not compatible with the argument list '(s_mainCharacter)'.

I followed a tutorial i am sure i have exactly what he had except for the name but i keep getting this error "Assets/Galaxy_Quest/Scripts/s_HUD.js(12,43): BCE0017: The best overload for the method 'UnityEngine.Object.FindObjectOfType(System.Type)' is not compatible with the argument list '(s_mainCharacter)'." here is my code for both files:

s_mainCharacter

static var SPEED = 7; static var TURBO = (SPEED *2); var rotateSpeed = 3.0; var bullitPrefab:Transform;

 var pHealth : int;
 var pScore : int;
 var pLife : int;
 var pPower : int;

 function Update () {

 var controller : CharacterController = GetComponent(CharacterController);
 // Rotate around y - axis
 transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
 // Move forward / backward
 var forward = transform.TransformDirection(Vector3.forward);
 var curSpeed = SPEED * Input.GetAxis ("Vertical");
 controller.SimpleMove(forward * curSpeed);

 if(Input.GetButtonDown("Jump")){
     //var bullit = Instantiate(bullitPrefab, GameObject.Find("leftSpawnPoint").transform.position, Quaternion.identity);
     var bullit = Instantiate(bullitPrefab, GameObject.Find("rightSpawnPoint").transform.position, Quaternion.identity);
     bullit.rigidbody.AddForce(transform.forward * 2000);
 }

}

function damageTaken(totalDamage : int){ pHealth -= totalDamage; if(pHealth <= 0){ if(pLife <=0){ killPlayer(); } else { pLife --; } }

}

function killPlayer(){ print("YOU DIED"); }

function addScore(totalScore : int){ pScore += totalScore; }

function getStatus(send : int){ switch (send){ case 1: return pLife; break; case 2: return pHealth; break; case 3: return pPower; break; case 4: return pScore; break;
} }

s_HUD.js

private var s_mainCharacter : s_mainCharacter;

var playerLife_pos = Vector2(0,0); var playerHealth_pos = Vector2(0,0); var playerPower_pso = Vector2(0,0); var playerScore_pos = Vector2(0,0);

function Update () { }


//I get error in the Awake function everything else works


function Awake(){

 s_mainCharacter = FindObjectOfType(s_mainCharacter); 

}

function OnGUI(){ var playerLife = s_mainCharacter.getStatus(1); var playerHealth = s_mainCharacter.getStatus(2); var playerPower = s_mainCharacter.getStatus(3); var playerScore = s_mainCharacter.getStatus(4);

 GUI.Label(Rect(playerLife_pos.x,playerLife_pos.y,100,100), playerLife.ToString());
 GUI.Label(Rect(playerHealth_pos.x,playerHealth_pos.y,100,100), playerHealth.ToString());
 GUI.Label(Rect(playerPower_pso.x,playerPower_pso.y,100,100), playerScore.ToString());
 GUI.Label(Rect(playerScore_pos.x,playerScore_pos.y,100,100), playerPower.ToString());

}

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 Peter G · Jul 25, 2010 at 06:10 PM 1
Share

I don't think this is the problem, but it isn't normally a good convention to name a variable the same thing as its type. It just gets confusing like var float : float;

1 Reply

· Add your reply
  • Sort: 
avatar image
3

Answer by Mike 3 · Jul 25, 2010 at 06:16 PM

You named your variable the same as the class

Change it to something else and it should work

Edit for the sake of clarity:

The error you're getting is because you're trying to pass an instance of the class instead of the class type itself to the function

Example which doesn't work:

class a extends MonoBehaviour { var b : b;

 function Start ()
 {
     b = GetComponent(b);
 }

}

class b { }

Example which works:

class a extends MonoBehaviour { var _b : b;

 function Start ()
 {
     _b = GetComponent(b);
 }

}

class b { }

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 Peter G · Jul 27, 2010 at 12:16 PM 1
Share

Ok, I voted you up, because I figured I may as well test his code, and you were correct. Funny thing is I posted something similar to that as a comment like 15 $$anonymous$$utes after he asked the question and he never commented anything back. I said "I don't think that's the problem", but it actually was anyway and if he had read it and tried it, this whole debate would be over. The other thing is that the line number is wrong. He formatted his code before he posted here, because even if you remove the comments, the error is on line 13. So I'm not sure what else he added or removed.

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

No one has followed this question yet.

Related Questions

No overload for method 'ToString' takes '1' arguments: YES IT DOES! 2 Answers

What does BCE0004: Ambiguous reference error mean? 3 Answers

Unexpected Token: Collider. 1 Answer

Lerpz tutorial multiple errors.HELP!!!! 4 Answers

'motorTorque' is not a member of 'System.Type'. 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