Explain the functionality of each line of code in the following C# script- using System.Collections; using System.Collections.Generic; using UnityEngine; public class Movement2D : MonoBehaviour {     public float moveSpeed = 3f;     public float jumpForce = 5f;     public bool isGrounded;     private bool doubleJump;     private bool canDash = true;     private bool isDashing;     private float dashingPower = 24f;     private float dashingTime = .2f;     private float dashingCooldown = 1f;     private bool isWallJumping;     private float wallJumpingDirection;     private float wallJumpingTime;     private float wallJumpingCounter;     private float wallJumpingDuration = .04f;     private Vector2 wallJumpingPower = new Vector2(8f, 16f);     [SerializeField] private Rigidbody2D rb;     [SerializeField] private TrailRenderer tr;     [SerializeField] private Transform wallCheck;     [SerializeField] private LayerMask wallLayer;     private SpriteRenderer sprite;     public void Start()     {         sprite = gameObject.GetComponent();     }     private void Update()     {              if (isDashing)         {             return;         }         WallJump();         Jump();         Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);         transform.position += movement * Time.deltaTime * moveSpeed;         if (Input.GetAxisRaw("Horizontal") < 0)         {             sprite.flipX = true;         }         else if (Input.GetAxisRaw("Horizontal") > 0)         {             sprite.flipX = false;         }         if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)         {             StartCoroutine(Dash());         }         if (!isWallJumping)         {             rb.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, rb.velocity.y);         }     }     void Jump()     {         if (Input.GetButtonDown("Jump") && isGrounded)         {             gameObject.GetComponent().velocity = (new Vector2(0f, jumpForce));             doubleJump = true;         }         else if (Input.GetButtonDown("Jump") && doubleJump)         {             gameObject.GetComponent().velocity = (new Vector2(0f, jumpForce));             doubleJump = false;         }     }          private IEnumerator Dash()     {         canDash = false;         isDashing = true;         float orignialGravity = rb.gravityScale;         rb.gravityScale = 0f;         rb.velocity = new Vector3(Input.GetAxis("Horizontal") * dashingPower, 0f);         tr.emitting = true;         yield return new WaitForSeconds(dashingTime);         tr.emitting = false;         rb.gravityScale = orignialGravity;         isDashing = false;         yield return new WaitForSeconds(dashingCooldown);         canDash = true;     }     private void WallJump()     {         if (Input.GetButtonDown("Jump") && wallJumpingCounter > 0f)         {             isWallJumping = true;             rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);             wallJumpingCounter = 0f;             if (Input.GetAxisRaw("Horizontal") != wallJumpingDirection)             {                 sprite.flipX = !sprite.flipX;             }             Invoke(nameof(StopWallJumping), wallJumpingDuration);         }     }     private void StopWallJumping()     {         isWallJumping = false;     } }

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

Explain the functionality of each line of code in the following C# script-

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

public class Movement2D : MonoBehaviour
{
    public float moveSpeed = 3f;
    public float jumpForce = 5f;
    public bool isGrounded;
    private bool doubleJump;

    private bool canDash = true;
    private bool isDashing;
    private float dashingPower = 24f;
    private float dashingTime = .2f;
    private float dashingCooldown = 1f;

    private bool isWallJumping;
    private float wallJumpingDirection;
    private float wallJumpingTime;
    private float wallJumpingCounter;
    private float wallJumpingDuration = .04f;
    private Vector2 wallJumpingPower = new Vector2(8f, 16f);

    [SerializeField] private Rigidbody2D rb;
    [SerializeField] private TrailRenderer tr;
    [SerializeField] private Transform wallCheck;
    [SerializeField] private LayerMask wallLayer;

    private SpriteRenderer sprite;

    public void Start()
    {
        sprite = gameObject.GetComponent<SpriteRenderer>();
    }
    private void Update()
    {
    
        if (isDashing)
        {
            return;
        }

        WallJump();
        Jump();
        Vector3 movement = new Vector3(Input.GetAxis("Horizontal"), 0f, 0f);
        transform.position += movement * Time.deltaTime * moveSpeed;

        if (Input.GetAxisRaw("Horizontal") < 0)
        {
            sprite.flipX = true;
        }
        else if (Input.GetAxisRaw("Horizontal") > 0)
        {
            sprite.flipX = false;
        }

        if (Input.GetKeyDown(KeyCode.LeftShift) && canDash)
        {
            StartCoroutine(Dash());
        }

        if (!isWallJumping)
        {
            rb.velocity = new Vector2(Input.GetAxisRaw("Horizontal") * moveSpeed, rb.velocity.y);
        }
    }

    void Jump()
    {

        if (Input.GetButtonDown("Jump") && isGrounded)
        {
            gameObject.GetComponent<Rigidbody2D>().velocity = (new Vector2(0f, jumpForce));
            doubleJump = true;
        }
        else if (Input.GetButtonDown("Jump") && doubleJump)
        {
            gameObject.GetComponent<Rigidbody2D>().velocity = (new Vector2(0f, jumpForce));
            doubleJump = false;
        }
    }
    
    private IEnumerator Dash()
    {
        canDash = false;
        isDashing = true;
        float orignialGravity = rb.gravityScale;
        rb.gravityScale = 0f;
        rb.velocity = new Vector3(Input.GetAxis("Horizontal") * dashingPower, 0f);
        tr.emitting = true;
        yield return new WaitForSeconds(dashingTime);
        tr.emitting = false;
        rb.gravityScale = orignialGravity;
        isDashing = false;
        yield return new WaitForSeconds(dashingCooldown);
        canDash = true;
    }


    private void WallJump()
    {
        if (Input.GetButtonDown("Jump") && wallJumpingCounter > 0f)
        {
            isWallJumping = true;
            rb.velocity = new Vector2(wallJumpingDirection * wallJumpingPower.x, wallJumpingPower.y);
            wallJumpingCounter = 0f;

            if (Input.GetAxisRaw("Horizontal") != wallJumpingDirection)
            {
                sprite.flipX = !sprite.flipX;
            }

            Invoke(nameof(StopWallJumping), wallJumpingDuration);
        }
    }

    private void StopWallJumping()
    {
        isWallJumping = false;
    }
}

Expert Solution
Step 1: Concept of Unity:

It is possible to design, produce, and deploy interactive experiences across a variety of platforms using Unity, a strong and well-liked game creation platform. It is renowned for its adaptability, supporting simulations, virtual reality, augmented reality, and 3D and 2D game production. For developers and artists, Unity's user-friendly interface and wide selection of assets make it available, and its powerful scripting features enable the creation of unique game logic. 

steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Generic Type
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
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