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 /
avatar image
0
Question by GoodGuyA · Oct 03, 2015 at 06:08 AM · unity 5unity 2dcolliderstutorialroguelike

Modification to Unity2D Roguelike

Hello all. I followed through with the Unity2D tutorial on creating a roguelike game, though not so much because I was creating a game like it, but rather that I was attempting to find a simple solution to creating a world based on tiles. It works out very well for what is intended, however there is one big issue that's blocking me from being able to generalize the system.

To define interactions with an object, they use this block of code, which also refers to other Movable Object (check out this part of the code to figure out what I mean). First is the player, second is the enemy.

Player:

 protected override void OnCantMove<T>(T component)
     {
         Wall hitWall = component as Wall;
         hitWall.DamageWall(wallDamage);
     }

Enemy:

 protected override void OnCantMove<T>(T component)
     {
             PlayerTileMove hitPlayer = component as PlayerTileMove;
 
             hitPlayer.LoseHealth(playerDamage);
     }

Again, works well for the purposes of demonstration, but what I found is that you cannot define any secondary interactions within this code. I wanted my enemies to have the ability to knock down walls so I added a Debug.Log to find the "component" tag, but it only recognizes the tag for the object it can directly interact with (Player with walls, Enemies with Player).

Essentially it only recognizes the object which it can preform special actions on. This may be down to how the colliders work in each script (player movement and enemy movement).

Enemy Should Destroy Blocks:

     if (component.tag == "Wall")
     {
         Wall hitWall = component as Wall;
         hitWall.DamageWall(4);
     }

Player Should Damage Enemy:

     if (component.tag == "Enemy")
     {
         EnemyTileMove hitEnemy = component as EnemyTileMove;
         hitEnemy.LoseHealth(5);
     }

Can anyone explain why the OnCantMove function can only check for one type of object and/or how to get around that? Thanks for your time!

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 viperbone · Dec 29, 2015 at 01:37 PM 0
Share

@GoodGuyA isn't it the case that in the Player "Update"-method the following line is written Attempt$$anonymous$$ove<Wall> (horizontal, vertical); -> When you check in the Attempt$$anonymous$$ove base method (in the $$anonymous$$ovingObject class) there you can see that OnCant$$anonymous$$ove is called with the type which was given in Attempt$$anonymous$$ove. Because in Player script there is "Wall" passed to this method the player only reacts on walls.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TheBonZi · Apr 01, 2016 at 08:37 PM

How easy way to see what we should be given in the "Attempt Move (horizontal, vertical);" Sorry for digging up an old post.

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

35 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

Related Questions

"buddies" multiplying, can't find what's wrong with my script 1 Answer

unable to open example project 0 Answers

Sprite Bug when move 1 Answer

High-score Saving Issue 2 Answers

Multiplayer FPS version of unity networking tutorial? Using rigidbodies- see project link 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