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 RandomDeveloper · Jan 31, 2013 at 11:52 PM · functioncalling

How to call functions?

Hello, I've made a script that tries to access another script to do damage to an enemy and I've hit a bump in the road. I have a script thats attached to my camera which contains a Update function that lets you select an enemy and also it has an else statement. That else statement's supposed to run a function called HitTarget if you press 1. I keep having a error when I run the game. I don't get what i'm doing wrong but its probably a simple mistake. Heres the two scripts that i have.

 //Targeting.js attached to camera
 var target : GameObject; //The target you want to attack
 var EnemyTargetted : boolean = false;
 public var damage = 7;
 
 public var health = 74;
  
 function Update (){
 //find the enemy you want to attack
     var hit : RaycastHit;
     if(Input.GetButtonDown("Fire1")){
         var ray : Ray = gameObject.camera.ScreenPointToRay(Input.mousePosition);
         if(Physics.Raycast(ray, hit)){
             if(hit.collider.tag == "Enemy"){
                 target = hit.collider.gameObject;
                 EnemyTargetted = true;
 
             }       
             else{
             //normal attack by pressing 1
             if(Input.GetKeyDown ("1")) {
             HitTarget ();
             }
             }        
         }
     }
     
     
 }
 
 function HitTarget (damage : int) {
     target.GetComponent(NewBehaviourScript).Hit(damage);
 }

Heres the script that the enemy has (still in progress).

 var damage = 3;
 var InSight : boolean;
 var startingHealth = 75;
 private var enemyHealth : int;
 
 function Start () {
     enemyHealth = startingHealth;
 }
 
 function Hit (damage : int) {
     enemyHealth -= damage;
     if (enemyHealth <= 0) {
         Destroy (gameObject);
     }
 }
 
 function OnTriggerEnter (other : Collider){
     if(other.tag == "Player"){
        InSight = true;
     }
 }
 
 function OnTriggerExit (other: Collider){
     if(other.tag == "Player"){
         InSight = false;
     }
 }
 

I get this error when i try to run the game :The best overload for the method 'Targeting.HitTarget(int)' is not compatible with the argument list '()'.

Please help I can't continue my game without this being fixed.

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

Answer by Eric5h5 · Feb 01, 2013 at 12:00 AM

As the error says, you're doing "`HitTarget()`", but the function you have requires that you supply an int.

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 RandomDeveloper · Feb 01, 2013 at 12:07 AM 0
Share

How would i supply an int for damage?

avatar image gfvfubb · Feb 01, 2013 at 12:10 AM 0
Share

function HitTarget (damage : int) {

That declares HitTarget to require an integer for damage. You're calling HitTarget() with an empty set of arguments. Try:

var dmgamount : int = 10; HitTarget(dmgamount);

avatar image Eric5h5 · Feb 01, 2013 at 12:10 AM 1
Share

By putting in a number.

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

11 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

Related Questions

why is part of my script getting called as if it was in the Start function? 2 Answers

Pre-Built versus Custom functions 1 Answer

Calling functions from a class - Curious issue 1 Answer

Calling a function in another script. 1 Answer

Can I do recursion in unity3d compiler using javascript? 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