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 /
  • Help Room /
This question was closed Sep 18, 2016 at 08:17 PM by lexmcnevan for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by lexmcnevan · Jul 14, 2016 at 10:59 PM · scripting problemanimatorscriptingbasicsanimationsscriptingproblem

Attack Script

Hi, I'm new in Unity and I'd like to create a simple game: a main character with a couple of attacks (with a sword) to kill aliens. For now, she stands in the "Idle" position and she "walks" but I've been searching and following some tutorials and trying out some scripts for the attacks but none of them seems to work. Anyone could help me or send me a basic script to do the attacks, the animations of the attacks are already done, they're called "AttackNear" and "AttackMiddle" and I'd like them to be activated with mouse left and right button for example. PLEASE I NEED HELP!! Also, this is how I've set the Animator: alt text

animator.png (226.1 kB)
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

2 Replies

  • Sort: 
avatar image
1

Answer by MichaelNielsenDev · Jul 14, 2016 at 11:20 PM

No one is going to write your scripts for you, but I can give you some tips and resources to start.

If you want to one thing to attack another, typically you want the attacker to have a method on one of their scripts that reduces the health of the thing they are attacking. Health can be a public variable for any classes that can be attacked.

Accessing what you are hitting can be done a few different ways. My favorite and the most simple way is to assign tags to gameobjects. You'd tag enemies with the Enemy tag, and your player with the Player tag.

Then, you'd either use a raycast or OnCollisionEnter to get data on the thing you hit, and it's there that you check what tag that thing has. If it has the Enemy tag, you reduce their health by a certain amount.

Also, there's OnTriggerEnter, which functions like OnCollisionEnter but with trigger colliders. With these, make sure you mark the collider as a trigger, which you can do by going into the collider component of the gameobject you're interested in and check Is Trigger.

More info on Tags, Raycasts, OnCollsionEnter, and OnTriggerEnter: https://docs.unity3d.com/Manual/Tags.html https://docs.unity3d.com/ScriptReference/Physics.Raycast.html https://docs.unity3d.com/ScriptReference/Collider.OnCollisionEnter.html https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html

If all else fails, there are plenty of tutorials on youtube showing how to attack and damage things.

Here's one I recommend: https://www.youtube.com/watch?v=qwuPiaFU37w

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 theANMATOR2b · Jul 14, 2016 at 11:18 PM

Maybe a better option is you look at the learn section.

Specifically the animation learn section. Also in the live training section where several instances the trainer writes animation code.

Its better to learn how to do something instead of having someone do it for you.

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

Follow this Question

Answers Answers and Comments

75 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

Related Questions

The type or namespace function could not be found 1 Answer

Unity CharacterController.Move Issue 0 Answers

Set public gameobject by raycast hit target 1 Answer

How to rotate spine by the script, while an animation from the animator is playing? 1 Answer

NEED HELP ANIMATING PLAYER MOVEMENT 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