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 /
This question was closed Mar 14, 2017 at 07:46 PM by Bunny83 for the following reason:

Duplicate Question

http://answers.unity3d.com/questions/1325076/how-to-use-the-protected-override-void-functiont-c.html

avatar image
0
Question by Herculess · Mar 14, 2017 at 09:36 AM · functionsc# tutorialroguelike

How to use function (T component)

I am using the following two functions after following the Unity Roguelike tutorial and I am trying to modify it so that the player can attack the enemies. The problem comes in because im unfamiliar with the function(T component) function and im unsure of how to call it.

The AttemptMove() function checks if the player collides with anything and if its a wall, then the second function, OnCantMove() is called. How can I check what the 'hitComponent' is that is being passed into the OnCantMove() function so that I can create if statements for different objects.

Thanks guys.

     protected virtual void AttemptMove<T> (int xDir, int yDir)
              where T: Component
          {
              RaycastHit2D hit; 
              bool canMove= Move (xDir, yDir, out hit);
              if (hit.transform == null)
                  return;
      
              T hitComponent = hit.transform.GetComponent<T> ();
      
              if (!canMove && hitComponent != null)
                  OnCantMove (hitComponent); 
          }
      
  and `
             protected override void OnCantMove<T>(T component)
         {
  
          Wall hitWall = component as Wall;
          hitWall.DamageWall (wallDamage);
          animator.SetTrigger ("PlayerChop");
  
        }`
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 Bunny83 · Mar 14, 2017 at 07:45 PM 0
Share

Duplicate of this one:
http://answers.unity3d.com/questions/1325076/how-to-use-the-protected-override-void-functiont-c.html

1 Reply

  • Sort: 
avatar image
1

Answer by Deathdefy · Mar 14, 2017 at 06:49 PM

  protected void OnCantMove(T component)
     {
         Debug.Log(component.GetType());
 
         if(component is Transform)
         {
 
         }
     }

Should do the trick.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to use the protected override void function(T component) function 1 Answer

Respawning objects upon player death problems 2 Answers

Creating a new variable with custom function 1 Answer

C# utilities functions in other script 1 Answer

Array of gameobjects, loop through and call functions 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