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 giraffe1 · Apr 23, 2016 at 03:35 PM · c#interfaceabstract

Need help understanding a few c# concepts

From my reading, abstract classes are not instantiated. But I also read somewhere else that they do in fact instantiate as an object. I am not sure which is correct.

What is the 'this' keyword doing in this scenario? And why is the 'this' keyword only used on 'position'? If the author used it on 'position' why would he not apply it to 'id' & 'type'?

All help is appreciated.

 using UnityEngine;
 
 public abstract class Entity : MonoBehaviour, IEntity
 {
     public int id { get; set; }
 
     public EntityType type { get; set; }
 
     public Vector3 position
     {
         get { return this.transform.position; }
         set { this.transform.position = value; }
     }
 }

 public enum EntityType
 {
     Player,
 
     Enemy
 }



 using UnityEngine;
 
 public interface IEntity
 {
     int id { get; set; }
 
     EntityType type { get; set; }
 
     Vector3 position { get; set; }
 
     GameObject gameObject { get; }
 }

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 Owen-Reynolds · Apr 23, 2016 at 05:28 PM 0
Share

C# is a real program$$anonymous$$g language and Unity uses it pretty much exactly as anyone else does. This means you can find many detailed explanations of anything in non-Unity forums. Very, very easy to search using "C# blah-blah."

1 Reply

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

Answer by troien · Apr 23, 2016 at 04:11 PM

this is just to indicate that you want this class his variable/property/method etc. It is only required when you have 2 variables with the same name (in a different scope) and in all other cases it is optional and one could argue it adds clarity.

When inherriting, and overwriting, the base keyword can be used to distinguish this from the base where you inherrit from

 public class Example : MonoBehaviour
 {
     private int test;
 
     public void ExampleMethod(int test)
     {
         this.test = test; // set our private variable to our parameter
 
         test = test; // Set value of our parameter to value of our parameter. Your compiler will complain on this one
     }
 }

Abstact classes can't be instantiated themself. But they can be inherrited, and those inherrited classes can be instantiated (as long as they aren't abstract ofcourse).

But really, the links to the MSDN sections provide a much more in depth explanation about the subjects...

Comment
Add comment · Show 1 · 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 giraffe1 · Apr 23, 2016 at 04:28 PM 0
Share

Thank you very much for the explanation and example. I understand now!

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

135 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 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

Is it possible to change CustomPass variables via other script? 0 Answers

C# - Error " does not implement interface member" 2 Answers

What is a good way to create dynamic dropdown buttons? 0 Answers

Multiple PowerUps (One ItemBox) 0 Answers

C# Abstract methods with default parameters 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