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

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

how create EndLess game Like zombie Tsunami 1 Answer

2D Unity 5.1 shooting a bullet in the direction my player is facing. 2 Answers

Unity 5: 2D Platformer: Trigger/Collisions problem 0 Answers

My character is not taking damage. 1 Answer

Enemy movement in javascript? 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