• 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 CrispyArrow · Jun 06, 2016 at 05:08 AM · 2d-platformerextendimplement

How do I use Extends to update a subclass from its parent?

I am currently making a 2-d platformer mario-style unity game for college in which we are supposed to use multiple design patterns. Now at the moment, I am busy making a prototype pattern (which to my understanding is a pattern from which all "enemies" could extend from to reuse certain codes or functions.

When I try to extend a class from another class, however, it does not recognize "extends".

Is there something I am missing out on? I though the ':' in the class names is equal to "Implements", am I wrong about this?

I simply need to know how I let a class extend from another class, meaning it literally uses the methods in that class.

Here is the class from which I am trying to extend: using UnityEngine; using System.Collections;

 public abstract class Prototype : MonoBehaviour {
 
     int eHealth;
     int eScore;
 
     IMoveForward moveForward;
     ILookForward lookForward;
 
     public void SetMoveBehaviour(IMoveForward m)
     {
         this.moveForward = m;
     }
 
     public void SetLookBehaviour(ILookForward l)
     {
         this.lookForward = l;
     }
 
     //void SetJumpBehaviour()
 
     public int Health
     {
         get { return eHealth; }
         set { eHealth = value; }
     }
 
     public int Score
     {
         get { return eScore; }
         set { eScore = value; }
     }
 
     void Update()
     {
         SetLookBehaviour(lookForward);
         SetMoveBehaviour(moveForward);
     }
     //  public abstract Prototype Clone();
 }


And here is the class which is supposed to extend from said class:

 using UnityEngine;
 using System.Collections;
 using System;
 
 class BasicMovement : Prototype, IMoveForward {
   
     public float _speed = .5f;
 
     //send the speed value to the move interface
     public float speed
     {
         get
         {
             return _speed;
         }
 
         set
         {
             _speed = value;
         }
     }
 
     //implement the movement method
     public void MoveCharacter(Vector2 m)
     {
         m = new Vector2(transform.localScale.x, 0) * speed;
     }
 }

This class also implements an interface called (IMoveForward) (assuming ":" is actually "implements").

Sorry if I'm being somewhat vague it's just that I am not sure what I am supposed to do. right now the classes mentioned above are all working without errors, but I have no update function (which i would like to put in the Prototype class and from there update everything)

Please let me know if I need to specify more things, and basically what I am mostly trying to ask is: How can I extend from another class, so I can update the subclass through the extended class?

Thank you for your time and once again, let me know if I need to specify things.

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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Cant fix 2d wall jumping 0 Answers

Having a non teleport dash 2 Answers

Cant get dash attack working 0 Answers

How to fix strange 2D colliders behavior? 0 Answers

Tilemap Collision 2D colliding with ground. 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