Explain the functionality of each line of code in the provided C# scripts- using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class Healthbar : MonoBehaviour {     [SerializeField] private Health playerHealth;     [SerializeField] private Image totalHealthbar;     [SerializeField] private Image currentHealthbar;     private void Start()     {         totalHealthbar.fillAmount = playerHealth.currentHealth / 10;     }     private void Update()     {         currentHealthbar.fillAmount = playerHealth.currentHealth / 10;     } } using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class Health : MonoBehaviour {     [SerializeField] private float startingHealth;     public float currentHealth { get; private set; }     private Animator anim;     private void Awake()     {         currentHealth = startingHealth;         anim = GetComponent();     }     public void TakeDamage(float _damage)     {         currentHealth = Mathf.Clamp(currentHealth - _damage, 0, startingHealth);         if (currentHealth <= 0)         {                 anim.SetTrigger("death");             GetComponent().bodyType = RigidbodyType2D.Static;         }     }     private void OnCollisionEnter2D(Collision2D collision)     {         if (collision.gameObject.CompareTag("Spike Trap"))         {             TakeDamage(1);         }     }     private void RestartLevel()     {         SceneManager.LoadScene(SceneManager.GetActiveScene().name);     } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class GroundCheck : MonoBehaviour {     GameObject Player;     private void Start()     {         Player = gameObject.transform.parent.gameObject;     }     private void OnCollisionEnter2D(Collision2D collision)     {         if (collision.collider.tag == "Ground" ||                 collision.collider.tag == "Platform")         {             Player.GetComponent().isGrounded = true;         }     }     private void OnCollisionExit2D(Collision2D collision)     {         if(collision.collider.tag == "Ground"||                 collision.collider.tag == "Platform")             {             Player.GetComponent().isGrounded = false;             }     } } using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlatformManager : MonoBehaviour {     GameObject[] platforms;     GameObject currentPlatform;     int index;     public GameObject coin;     private void Start()     {         NewPlatform();     }     // Start is called before the first frame update     public void NewPlatform()     {         platforms = GameObject.FindGameObjectsWithTag("Platform");          index = Random.Range(0, platforms.Length);          currentPlatform = platforms[index];          coin.transform.position = new Vector2(currentPlatform.transform.position.x, currentPlatform.transform.position.y + 2f);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

Explain the functionality of each line of code in the provided C# scripts-

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Healthbar : MonoBehaviour
{
    [SerializeField] private Health playerHealth;
    [SerializeField] private Image totalHealthbar;
    [SerializeField] private Image currentHealthbar;

    private void Start()
    {
        totalHealthbar.fillAmount = playerHealth.currentHealth / 10;
    }

    private void Update()
    {
        currentHealthbar.fillAmount = playerHealth.currentHealth / 10;
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Health : MonoBehaviour
{
    [SerializeField] private float startingHealth;
    public float currentHealth { get; private set; }
    private Animator anim;

    private void Awake()
    {
        currentHealth = startingHealth;
        anim = GetComponent<Animator>();
    }

    public void TakeDamage(float _damage)
    {
        currentHealth = Mathf.Clamp(currentHealth - _damage, 0, startingHealth);

        if (currentHealth <= 0)
        {
                anim.SetTrigger("death");
            GetComponent<Rigidbody2D>().bodyType = RigidbodyType2D.Static;
        }

    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.gameObject.CompareTag("Spike Trap"))
        {
            TakeDamage(1);
        }
    }

    private void RestartLevel()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GroundCheck : MonoBehaviour
{
    GameObject Player;

    private void Start()
    {
        Player = gameObject.transform.parent.gameObject;
    }

    private void OnCollisionEnter2D(Collision2D collision)
    {
        if (collision.collider.tag == "Ground" ||
                collision.collider.tag == "Platform")
        {
            Player.GetComponent<Movement2D>().isGrounded = true;
        }
    }

    private void OnCollisionExit2D(Collision2D collision)
    {
        if(collision.collider.tag == "Ground"||
                collision.collider.tag == "Platform")
            {
            Player.GetComponent<Movement2D>().isGrounded = false;
            }
    }

}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlatformManager : MonoBehaviour
{
    GameObject[] platforms;
    GameObject currentPlatform;
    int index;

    public GameObject coin;

    private void Start()
    {
        NewPlatform();
    }
    // Start is called before the first frame update
    public void NewPlatform()
    {
        platforms = GameObject.FindGameObjectsWithTag("Platform"); 
        index = Random.Range(0, platforms.Length); 
        currentPlatform = platforms[index]; 
        coin.transform.position = new Vector2(currentPlatform.transform.position.x, currentPlatform.transform.position.y + 2f);
    }

}



Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education