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 Emo · May 01, 2011 at 09:23 AM · collisionenemyhealth

Unity health problem and enemy colision

My 1st problem is that the enemies aren't colliding with any game objects or themselves (they have a box collider and a character controller) they however do collide with my main character (player)


My 2nd problem is that i am currently have a health system , it works fine when there only one enemy, but when there are two ore more enemies, it doesn't work properly. It seams to create two instances of its self

(example the enemy does 10 damage on attack, when 2 enemies are attacking at once it should take away 20, but it takes away 10), currently a health script is applied to the enemy prefab, the health script contains the GUI and code.

i can do it when a GUI text is on the scene so i can store the values (this requires the enemies to be on the scene before game starts), but when i try to instantiate the prefab the script cant find the GUI text. (i try to add it to the script but it doesnt let me it still says none 2D texture.

code........ (in the enemy script, when an attack is delt this method is called )both of these scripts are attached to the enemy Prefab var damage=10;

function health(){

var health : healthScript= GetComponent(healthScript);

health.hp(damage);

}

in the healthScript var healthtexture=gameObject.Find ("100%");

function hp(damage){

health-=damage; if (health<1){ healthtexture.guiTexture.texture= health00;

}....

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 GesterX · May 01, 2011 at 02:22 PM 1
Share

Are your health and hp functions attached to scripts attached to the enemy? Are these functions intended to deal damage to the player or the enemy itself?

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Emo · May 06, 2011 at 10:30 AM

i have solved the health problem by myself, probelm was it was creating instances of the highscore

created an GUI Texture added a png called 100% added the healthscript (take away damage includes different images for different health)

var damageManager = GameObject.FindWithTag("100%"); damageManager.GetComponent(healthScript).applyDamage(10);

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 lhk · May 01, 2011 at 02:37 PM

I don't understand exactly what you've done. My suggestion would be to change the code like this

  • you create two scripts: "enemy.js" and "player.js"
  • enemy.js should look similar to this

    var player : GameObject ;

    function attack(damage : int) { player.broadcastMessage("applyDamage",damage); }

    player.js should look similar to this

    var hp : int =100;

    function applyDamage(damage : int) { hp-=damage; //deal with your GUI here }

    This way you get a neat cut between player and enemy. Moreover you can add new types of enemies very simple by just letting them sent applyDamage, too. However the most important thing is, that broadcastMessage tries to invoke applyDamage in every script on your player GameObject. Therefore when you try to implement animations you can add this method to your animation.js script and play an animation where your character backs away or stumbles.

    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 lhk · May 01, 2011 at 02:52 PM

    I made a few simple tests but on my machine Charactercontroller and Boxcollider worked together without problems. I don't know exactly what your problem is, so I can only guess:

    1. Are the enemies at the same heigth.
    2. Did you set one of the colliders to be a Trigger
    3. Did you make an ominous call to something like Physics.IgnoreCollision(). Maybe to deal with the attacks, to shoot a bullet ,...

    I'm sorry I can't really help. If you provide more information I'll try to solve your problem, so far try:

    • Make a really simple script to just move an enemy in one direction and provoke a "simple" collision. Turn off all the other scripts to make sure none of them is interfering. If the collision works, it is likely that one of your scripts is the problem
    • Check everything twice. Maybe add another collider instead of the Boxcollider and remove the Boxcollider.
    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

    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

    Enemy not taking damage on collisions. 2 Answers

    Enemy health not reducing on collision with bullet 0 Answers

    Lose health on collision 1 Answer

    How i make the player damage the enemy specific enemy he is colliding with 1 Answer

    EnemyHealth.js script not working... 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