Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////////////////Second Part//////////////////////////////////////
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- // I'm always putting this self reference in order not get in ambiguity neither from the compiler's end or my end
- public class MyClass : MonoBehaviour
- {
- public Animator anim;
- [HideInInspector]
- bool gameNotPaused = true;
- void Start()
- {
- anim.SetBool("Hide", false);
- }
- private void OnTriggerEnter2D(Collider2D collision)
- {
- if(collision.name == "player" && gameNotPaused)
- {
- // GameObject o = gameObject;
- if (!(this.GetComponent<LeftRight>()))
- {
- this.GetComponent<LeftRight>().RangeOfMovement = 0;
- }
- anim.SetBool("Hide", true);
- }
- }
- private void OnTriggerExit2D(Collider2D collision)
- {
- // GameObject o = gameObject;
- if (!(this.GetComponent<LeftRight>()))
- {
- this.GetComponent<LeftRight>().RangeOfMovement = 9.5f;
- }
- anim.SetBool("Hide", false);
- }
- }
- ////////////////////////////////////// Third Part //////////////////////////////////////
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- // Make sure there is a Component of type Rigidbody2D on the Object
- [RequireComponent(typeof(Rigidbody2D))]
- public class Part3Script : MonoBehaviour
- {
- // Rigidbody2D Component Declaration
- Rigidbody2D rb;
- // Spawned Objects Count
- int count = 0;
- // Object to be Spawned
- public GameObject obj;
- // Start is called before the first frame update
- void Start()
- {
- // Assign the Rigidbody2D Component that is sitting on the Object
- rb = this.GetComponent<Rigidbody2D>();
- }
- // Update is called once per frame
- void Update()
- {
- // Check if there are no spawned Objects
- if (count<=0)
- {
- // Just a log msg to Indicate functionality
- Debug.Log("Your Pals are on the way ... ");
- }
- // Get input for Spawning (Don't know why P is exactly but I like it xD)
- if (Input.GetKeyDown("p") || count < 5)
- {
- SpawnObject(obj);
- count++;
- }
- }
- // Detecting Collisions
- void OnCollisionEnter2D(Collision2D collision)
- {
- Debug.Log(collision.gameObject.name + " hit you .... Run .. ");
- }
- // Function to spawn Objects
- void SpawnObject(GameObject obj)
- {
- // Create an Instance of the reference Object
- GameObject pickup = GameObject.Instantiate<GameObject>(obj);
- // Set the transform for the spawned object between two random limits
- pickup.transform.position = new Vector3(
- this.transform.position.x,
- Random.Range(this.transform.position.y-3, this.transform.position.y+3),
- this.transform.position.z
- );
- }
- }
- /////////////////////////////// Fourth Part ///////////////////////////////////////////
- using System;
- // I'm always putting this self reference in order not get in ambiguity neither from the compiler's end or my end
- // Parent Class
- public class Object
- {
- // Common members so they have to be public in order to be shared between all direct or indirect derived classes
- public string name;
- public string description;
- public int quantity;
- }
- // Derived Class
- public class Table : Object
- {
- // Setting initial values for the table object in the class constructor
- public Table()
- {
- this.numOfLegs = 4;
- this.hasSideHands = true;
- }
- private int numOfLegs;
- private bool hasSideHands;
- public void SetInfo(int numberOfLegs, bool SideHanded)
- {
- numOfLegs = numberOfLegs;
- hasSideHands = SideHanded;
- }
- public int GetNumOfLegs()
- {
- return this.numOfLegs;
- }
- }
- // Child of the derived class
- public class KitchenTable : Table
- {
- // Setting Initial Values for the members in the class constructor
- public KitchenTable()
- {
- this.hasKnives = true;
- this.numOfTaps = 2;
- }
- private bool hasKnives;
- private int numOfTaps;
- public void SetInfo(bool hasKnives, int numOfTaps)
- {
- this.hasKnives = hasKnives;
- this.numOfTaps = numOfTaps;
- }
- public int GetNumOfTaps()
- {
- return this.numOfTaps;
- }
- public bool GetHasKnives()
- {
- return this.hasKnives;
- }
- }
- public class Program
- {
- public static void Main(string[] args)
- {
- // creating object from the child of the derived class
- KitchenTable tableObj = new KitchenTable();
- // Setting properties inherited from original parent class
- tableObj.name = "Kitchen Table";
- tableObj.description = "Table for the Kitchen";
- tableObj.quantity = 4;
- // Accessing functions from the object class
- Console.WriteLine("Number of taps in the kitchen table are " + tableObj.GetNumOfTaps());
- Console.WriteLine("Does the table have knives ?? " + tableObj.GetHasKnives());
- // while there is legs, keep decreasing them
- while(tableObj.quantity != 0)
- {
- Console.WriteLine("Cutting Leg " + tableObj.quantity);
- tableObj.quantity--;
- if (tableObj.quantity == 0)
- {
- Console.WriteLine("Table Has no legs .. LOL\n");
- }
- }
- // May be can do some logic in each option but in order to be simple I'll just leave it like this
- int ch;
- Console.WriteLine("Choose a lucky number from 1 to 3");
- ch = Convert.ToInt32(Console.ReadLine());
- switch (ch)
- {
- case 1:
- Console.WriteLine("You Choosed Luck Number " + ch);
- break;
- case 2:
- Console.WriteLine("You Choosed Luck Number " + ch);
- break;
- case 3:
- Console.WriteLine("You Choosed Luck Number " + ch);
- break;
- default:
- Console.WriteLine("Choose from the provided numbers ... ");
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement