Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AshwinTheGammer · Nov 22, 2017 at 02:26 AM · unity 5scripting problemfpsdamagescript error

[Help!]Unity FPS Health script error.

I want to give and receive damage from my AI

This is my AI`s gun script

  IEnumerator ApplyDamage()
         {
             //Reduce the enemy's health
             //Does NOT travel up the heirarchy.  
             if (hit.transform.tag != friendlyTag)
             {
                 //Uncomment for RFPS
                
                if (hit.collider.gameObject.GetComponent<HealthingScript>())
                 {
                     hit.collider.gameObject.GetComponent<HealthingScript>().PlayerDamage(damage);
                }
                 
 
                 hit.collider.SendMessage(damageMethodName, damage, SendMessageOptions.DontRequireReceiver);
             }
 
             //Produce the appropriate special effect
             if (hit.transform.tag == hitEffectTag && hitEffect)
             {
                     GameObject currentHitEffect = (GameObject)(Instantiate(hitEffect, hit.point, myTransform.rotation));
                     GameObject.Destroy(currentHitEffect, hitEffectDestroyTime);
             }
             else if (missEffect)
             {
                 GameObject currentMissEffect = (GameObject)(Instantiate(missEffect, hit.point + hit.normal * 0.01f, Quaternion.LookRotation(hit.normal)));
                 GameObject.Destroy(currentMissEffect, missEffectDestroyTime);
             }
             this.enabled = false;
             yield return null;
 
             //Wait a fram to apply forces as we need to make sure the thing is dead
             if (hit.rigidbody)
                 hit.rigidbody.AddForceAtPosition(myTransform.forward * bulletForce, hit.point, ForceMode.Impulse);
 
             //Linger around for a while to let the trail renderer dissipate (if the bullet has one.)
             Destroy(gameObject, timeToDestroyAfterHitting);
         }

My player`s health script`s name is HealthingScript.js and there is ApplyDamage method like this

function PlayerDamage (damage : int) { if (hitPoints < 0.0) return;

 hitPoints -= damage;
 aSource.PlayOneShot(painSound, 1.0);
 t = 2.0;        
 
 if (hitPoints <= 0.0) Die();

}

and it show me error like this UnityEngine.Component' does not contain a definition for HealthingScript and no extension method HealthingScript of type `UnityEngine.Component' could be found. Are you missing an assembly reference?

Any comment and answer is appreciated here. Thanks in Advance.

Comment
Add comment · Show 9
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 EDevJogos · Nov 22, 2017 at 02:37 AM 0
Share

Is the name of class of HealthingScript.cs = HealthingScript ?

avatar image AshwinTheGammer EDevJogos · Nov 22, 2017 at 03:42 AM 0
Share

@Search HealthingScript is the name of script. Plz help!

avatar image EDevJogos AshwinTheGammer · Nov 23, 2017 at 04:20 AM 0
Share

I'm trying to replicate the same error message, but no luck. I thought it could be because of the use of some deprecated variable, or the name of the class on the .cs be different from the name of the .cs But the error messages they return are different than the one you posted.

avatar image jchester07 · Nov 23, 2017 at 06:04 AM 0
Share

Can you post the whole error?

So we can easily check which line the error is calling.

Also the whole code of HealthingScript please.

You are also using JavaScript, right?

avatar image AshwinTheGammer jchester07 · Nov 23, 2017 at 11:19 AM 0
Share

@jchester07 yes you are right my gun script have written into javascript and my Ai gun script is written into C#

avatar image jchester07 · Nov 23, 2017 at 06:13 AM 0
Share

wait. I thought Search was assu$$anonymous$$g it's a cs script.

but you said your player's health script's name is HealthingScript*.cs*

but why are you using function PlayerDamage (damage: int). That's a JavaScript Syntax.

avatar image AshwinTheGammer jchester07 · Nov 23, 2017 at 11:21 AM 0
Share

function PlayerDamage (damage: int). this is my player health script (HealthingScript written into javascript).

avatar image AshwinTheGammer jchester07 · Nov 23, 2017 at 11:29 AM 0
Share

@jchester07 Sorry by mistake I had written that my HelathingScript is written in to c# but no my script is written into javascript.

avatar image EDevJogos AshwinTheGammer · Nov 23, 2017 at 06:00 PM 0
Share

So you're in a C# class trying to acess a JS script? if that's so, take a look at this answer and you'll find your solution.

https://answers.unity.com/questions/48874/accessing-javascript-variable-from-c-and-vice-vers.html

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by JunaidGhani · Nov 23, 2017 at 07:28 AM

Well It's not a condition i think -> if (hit.collider.gameObject.GetComponent())

you are getting HealthingScript component of the hitted object, thats all.

Use something like this:

if(hit.collider.gameobject.tag.Equals ( ("Player") || ("Enemy") )

{

hit.collider.gameObject.GetComponent().PlayerDamage(damage);

}

@AshwinTheGammer

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 AshwinTheGammer · Dec 02, 2017 at 05:39 AM 0
Share

@JunaidGhani I didn`t understand plz write it in the form of code. Properly

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

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

Related Questions

Draw call minimizer 1 Answer

"Only assignment, call, increment, decrement and new object expressions can be used as statements" 1 Answer

Reference DLL's 1 Answer

MY FPSE`S fps is not moving need help! I tried all solutions! 0 Answers

How to follow a target (prefab) with the visual scripting: Behavior machine Pro? 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