Advertisement
Nader1414518

YAMI Test Parts

Aug 23rd, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.81 KB | None | 0 0
  1. ///////////////////////////////////Second Part//////////////////////////////////////
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5.  
  6.  
  7. // I'm always putting this self reference in order not get in ambiguity neither from the compiler's end or my end
  8. public class MyClass : MonoBehaviour
  9. {
  10.     public Animator anim;
  11.     [HideInInspector]
  12.     bool gameNotPaused = true;
  13.  
  14.     void Start()
  15.     {
  16.         anim.SetBool("Hide", false);
  17.     }
  18.  
  19.     private void OnTriggerEnter2D(Collider2D collision)
  20.     {
  21.      if(collision.name == "player" && gameNotPaused)
  22.     {
  23.         // GameObject o = gameObject;
  24.         if (!(this.GetComponent<LeftRight>()))
  25.         {
  26.             this.GetComponent<LeftRight>().RangeOfMovement = 0;
  27.         }
  28.         anim.SetBool("Hide", true);
  29.       }
  30.     }
  31.     private void OnTriggerExit2D(Collider2D collision)
  32.     {
  33.         // GameObject o = gameObject;
  34.         if (!(this.GetComponent<LeftRight>()))
  35.         {
  36.             this.GetComponent<LeftRight>().RangeOfMovement = 9.5f;
  37.         }
  38.        
  39.         anim.SetBool("Hide", false);
  40.     }
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. ////////////////////////////////////// Third Part //////////////////////////////////////
  54. using System.Collections;
  55. using System.Collections.Generic;
  56. using UnityEngine;
  57.  
  58. // Make sure there is a Component of type Rigidbody2D on the Object
  59. [RequireComponent(typeof(Rigidbody2D))]
  60. public class Part3Script : MonoBehaviour
  61. {
  62.     // Rigidbody2D Component Declaration
  63.     Rigidbody2D rb;
  64.     // Spawned Objects Count
  65.     int count = 0;
  66.     // Object to be Spawned
  67.     public GameObject obj;
  68.    
  69.    
  70.     // Start is called before the first frame update
  71.     void Start()
  72.     {
  73.         // Assign the Rigidbody2D Component that is sitting on the Object
  74.         rb = this.GetComponent<Rigidbody2D>();
  75.        
  76.     }
  77.    
  78.     // Update is called once per frame
  79.     void Update()
  80.     {
  81.         // Check if there are no spawned Objects
  82.         if (count<=0)
  83.         {
  84.           // Just a log msg to Indicate functionality
  85.           Debug.Log("Your Pals are on the way ... ");
  86.         }
  87.        
  88.         // Get input for Spawning (Don't know why P is exactly but I like it xD)
  89.         if (Input.GetKeyDown("p") || count < 5)
  90.         {
  91.           SpawnObject(obj);
  92.           count++;
  93.         }
  94.     }
  95.  
  96.     // Detecting Collisions
  97.     void OnCollisionEnter2D(Collision2D collision)
  98.     {
  99.       Debug.Log(collision.gameObject.name + " hit you .... Run .. ");
  100.     }
  101.    
  102.     // Function to spawn Objects
  103.     void SpawnObject(GameObject obj)
  104.     {
  105.       // Create an Instance of the reference Object
  106.       GameObject pickup = GameObject.Instantiate<GameObject>(obj);
  107.       // Set the transform for the spawned object between two random limits
  108.       pickup.transform.position = new Vector3(
  109.         this.transform.position.x,
  110.         Random.Range(this.transform.position.y-3, this.transform.position.y+3),
  111.         this.transform.position.z
  112.       );
  113.     }
  114. }
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. /////////////////////////////// Fourth Part ///////////////////////////////////////////
  125. using System;
  126.  
  127. // I'm always putting this self reference in order not get in ambiguity neither from the compiler's end or my end
  128.  
  129. // Parent Class                
  130. public class Object
  131. {
  132.     // Common members so they have to be public in order to be shared between all direct or indirect derived classes
  133.     public string name;
  134.     public string description;
  135.     public int quantity;
  136. }
  137.  
  138. // Derived Class
  139. public class Table : Object
  140. {
  141.     // Setting initial values for the table object in the class constructor
  142.     public Table()
  143.     {
  144.         this.numOfLegs = 4;
  145.         this.hasSideHands = true;
  146.     }
  147.     private int numOfLegs;
  148.     private bool hasSideHands;
  149.     public void SetInfo(int numberOfLegs, bool SideHanded)
  150.     {
  151.         numOfLegs = numberOfLegs;
  152.         hasSideHands = SideHanded;
  153.     }
  154.     public int GetNumOfLegs()
  155.     {
  156.         return this.numOfLegs;
  157.     }
  158. }
  159.  
  160. // Child of the derived class
  161. public class KitchenTable : Table
  162. {
  163.     // Setting Initial Values for the members in the class constructor
  164.     public KitchenTable()
  165.     {
  166.         this.hasKnives = true;
  167.         this.numOfTaps = 2;
  168.     }
  169.     private bool hasKnives;
  170.     private int numOfTaps;
  171.     public void SetInfo(bool hasKnives, int numOfTaps)
  172.     {
  173.         this.hasKnives = hasKnives;
  174.         this.numOfTaps = numOfTaps;
  175.     }
  176.     public int GetNumOfTaps()
  177.     {
  178.         return this.numOfTaps;
  179.     }
  180.     public bool GetHasKnives()
  181.     {
  182.         return this.hasKnives;
  183.     }
  184. }
  185.  
  186. public class Program
  187. {
  188.     public static void Main(string[] args)
  189.     {
  190.         // creating object from the child of the derived class
  191.         KitchenTable tableObj = new KitchenTable();
  192.         // Setting properties inherited from original parent class
  193.         tableObj.name = "Kitchen Table";
  194.         tableObj.description = "Table for the Kitchen";
  195.         tableObj.quantity = 4;
  196.         // Accessing functions from the object class
  197.         Console.WriteLine("Number of taps in the kitchen table are " + tableObj.GetNumOfTaps());
  198.         Console.WriteLine("Does the table have knives ?? " + tableObj.GetHasKnives());
  199.        
  200.         // while there is legs, keep decreasing them
  201.         while(tableObj.quantity != 0)
  202.         {
  203.             Console.WriteLine("Cutting Leg " + tableObj.quantity);
  204.             tableObj.quantity--;
  205.             if (tableObj.quantity == 0)
  206.             {
  207.                 Console.WriteLine("Table Has no legs .. LOL\n");   
  208.             }
  209.         }
  210.        
  211.         // May be can do some logic in each option but in order to be simple I'll just leave it like this
  212.         int ch;
  213.         Console.WriteLine("Choose a lucky number from 1 to 3");
  214.         ch = Convert.ToInt32(Console.ReadLine());
  215.         switch (ch)
  216.         {
  217.             case 1:
  218.                 Console.WriteLine("You Choosed Luck Number " + ch);
  219.                 break;
  220.             case 2:
  221.                 Console.WriteLine("You Choosed Luck Number " + ch);
  222.                 break;
  223.             case 3:
  224.                 Console.WriteLine("You Choosed Luck Number " + ch);
  225.                 break;
  226.             default:
  227.                 Console.WriteLine("Choose from the provided numbers ... ");
  228.                 break;
  229.         }
  230.     }  
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement