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 justinc847 · Jan 03, 2014 at 01:20 AM · charactermodelgame object

Scripts don't work on model

I have scripts that make it so the player can attack the enemy and the enemy can attack the player. When i apply the scripts to a game object such as a cube or cylinder they work perfectly, but when i download a character model from the asset store and apply the scripts to them it doesn't work. How can I fix this?

Comment
Add comment · Show 6
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 HappyMoo · Jan 03, 2014 at 02:12 AM 0
Share

That's terribly unspecific. No script, you don't tell us what the script does to "work", you don't tell us how it fails - e.g. is the code still executed? Do Debug.Logs get printed? $$anonymous$$aybe some other script overrides movement or whatever your attack script does.

avatar image justinc847 · Jan 03, 2014 at 03:26 AM 0
Share

I have a script that tells the enemy to attack the player and cause health deduction, and another script that lets the player attack the enemy. The script that allows the enemy to attack the player works, but the other script does not. When the player attacks the enemy it is suppose to Destroy (gameObject); but it does not work when i import a character model. The script works fine on game objects such as a cube or sphere, but not an imported model.

avatar image Bloodyem · Jan 03, 2014 at 03:48 AM 0
Share

Ok, but this would still be much easier with a script. How are you telling the other objects that they've been hit, or that something is close? Because that method could be very important to your game objects.

avatar image justinc847 · Jan 03, 2014 at 04:06 AM 0
Share

Scripts

the script below uses a raycast to detect if an enemy is in range, if it is then the enemy takes damage.

function Update () { if (Input.GetButtonDown("Fire1")) { The$$anonymous$$ace.animation.Play("Attack2"); var hit : RaycastHit; if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), hit)) { Distance = hit.distance; if (Distance < $$anonymous$$axDistance) { hit.transform.Send$$anonymous$$essage("ApplyDammage", TheDammage, Send$$anonymous$$essageOptions.DontRequireReceiver); } } }


the script below calls the applydamage function from above and applys damage to the enemy

function Update () { if(Health <= 0) { Dead(); } }

function ApplyDammage (TheDammage : int) { Health -= TheDammage; }

function Dead() { Destroy (gameObject); }


the script below tells the enemy to attack the player, which works fine on a character model

function Start () { timeCheck = false; Ewaitseconds = Random.Range(EA$$anonymous$$Wait, EAmaxWait); }

function Update () { var Ehit : RaycastHit; if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Ehit)) { Edistance = Ehit.distance; if (Edistance < E$$anonymous$$axDistance) { Ewaittime(); if(timeCheck) { Ehit.transform.Send$$anonymous$$essage("ApplyPlayerDammage", Edammage, Send$$anonymous$$essageOptions.DontRequireReceiver); timeCheck = false; } } } }

if(!timeCheck) { yield WaitForSeconds(Ewaitseconds); timeCheck = true; }

function Ewaittime() { yield WaitForSeconds(Ewaitseconds); timeCheck = true; }

avatar image justinc847 · Jan 03, 2014 at 04:07 AM 0
Share

The comment made the scripts unbarable to read. Apologies.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by sparkzbarca · Jan 03, 2014 at 03:47 AM

based on the small amount of info provided i'd say your imported model lacks a collider.

A cube has one by default your imported model may not.

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 justinc847 · Jan 03, 2014 at 03:58 AM 0
Share

I have added colliders and that doesn't work. To get a little more specific I downloaded a character from the asset store and when i imported it into unity it had a parent object that was empty and two objects under that. One that was an object that only had one component which was a skin mesh renderer, and another that had editable geometry such for rotating hands etc. Ive tried everything and my script just doesn't work on it. The gameObject is not being destroyed even though it works on a simple cube or capsule.

avatar image sparkzbarca · Jan 03, 2014 at 04:17 AM 0
Share

your not using mesh colliders are you?

are you perhaps destroying something other than the parent, perhaps just a part of it.

maybe destroy(objecttobekilled.transform.root);

are you using on collision enter to detect and destory stuff?

did you debug.log what you hit to see if collisions are being detected?

it might be best to simply dropbox your project

avatar image justinc847 · Jan 03, 2014 at 04:31 AM 0
Share

Im not using $$anonymous$$esh colliders. Not destroying anything other than the parent. Tried the code with a transform variable and it didn't work. Not using on collision enter. I did debug log and the collision from the raycast is a success on objects such as capsules, cubes, ect. but not successful on imported objects. I now know that raycast is not picking up imported objects, what may cause that?

avatar image
0

Answer by justinc847 · Jan 03, 2014 at 07:15 AM

I've solved the problem, turns out it was because the colliders I added weren't big enough. Thanks for your help everyone!

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

22 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

Related Questions

Sharing animations with models 2 Answers

How can I find the position of my weapon? 1 Answer

How i can setup Character 0 Answers

How to make Pixel Graphics? 0 Answers

Character Animation Help 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