Answers for "unity list of actions"

0

unity list of actions

using System;
 using System.Collections.Generic;
 using UnityEngine;
 public class ActionClass : MonoBehaviour
 {
     private List<Action> actions;
 
     private void Start()
     {
         actions = new List<Action>();
 
         actions.Add(Action1);
         actions.Add(Action2);
         actions.Add(Action3);
     }
 
     private void Action1() { }
     private void Action2() { }
     private void Action3() { }
 }
Posted by: Guest on October-25-2021
0

unity list of actions

using System.Collections.Generic;
 using UnityEngine;
 
 public class AbilityClass : MonoBehaviour
 {
     private List<Ability> actions;
 
     private void Start()
     {
         actions = new List<Ability>();
 
         actions.Add(new WatchTV());
         actions.Add(new TakeBath());
         actions.Add(new MakeFood(3));
     }
 }
 
 public abstract class Ability
 {
     public abstract void Do();
 }
 
 public class WatchTV : Ability
 {
     public override void Do()
     {
         Debug.Log("Watching TV");
     }
 }
 
 public class TakeBath : Ability
 {
     public override void Do()
     {
         Debug.Log("Taking a bath");
     }
 }
 
 public class MakeFood : Ability
 {
     public int servings;
 
     public MakeFood(int servings)
     {
         this.servings = servings;
     }
 
     public override void Do()
     {
         Debug.Log("Making food");
     }
 }
Posted by: Guest on October-25-2021

Browse Popular Code Answers by Language