xplain the functionality of each line of code in the provided C# scripts- 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;     } } using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Video; [RequireComponent(typeof(VideoPlayer))] [RequireComponent(typeof(AudioSource))] public class PlayVideo : MonoBehaviour {     public VideoClip videoClip;     private VideoPlayer videoPlayer;     private AudioSource audioSource;     void Start()     {         videoPlayer = GetComponent();         audioSource = GetComponent();         videoPlayer.playOnAwake = false;         audioSource.playOnAwake = false;         videoPlayer.source = VideoSource.VideoClip;         videoPlayer.clip = videoClip;         videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;         videoPlayer.SetTargetAudioSource(0, audioSource);         videoPlayer.renderMode = VideoRenderMode.MaterialOverride;         videoPlayer.targetMaterialRenderer = GetComponent();         videoPlayer.targetMaterialProperty = "_MainTex";     }     void Update()     {         if (Input.GetButtonDown("Jump"))             PlayPause();     }     private void PlayPause()     {         if (videoPlayer.isPlaying)             videoPlayer.Pause();         else             videoPlayer.Play();     } } using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; public class NewBehaviourScript : MonoBehaviour {     // Start is called before the first frame update     void Start()     {              }     // Update is called once per frame     void Update()     {              }     public void LoadOnClick (int sceneIndex)     {         SceneManager.LoadScene(sceneIndex);     }

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 provided C# scripts-

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;
    }
}

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

[RequireComponent(typeof(VideoPlayer))]
[RequireComponent(typeof(AudioSource))]

public class PlayVideo : MonoBehaviour
{
    public VideoClip videoClip;

    private VideoPlayer videoPlayer;
    private AudioSource audioSource;

    void Start()
    {
        videoPlayer = GetComponent<VideoPlayer>();
        audioSource = GetComponent<AudioSource>();

        videoPlayer.playOnAwake = false;
        audioSource.playOnAwake = false;

        videoPlayer.source = VideoSource.VideoClip;
        videoPlayer.clip = videoClip;

        videoPlayer.audioOutputMode = VideoAudioOutputMode.AudioSource;
        videoPlayer.SetTargetAudioSource(0, audioSource);

        videoPlayer.renderMode = VideoRenderMode.MaterialOverride;
        videoPlayer.targetMaterialRenderer = GetComponent<Renderer>();
        videoPlayer.targetMaterialProperty = "_MainTex";
    }

    void Update()
    {

        if (Input.GetButtonDown("Jump"))
            PlayPause();
    }

    private void PlayPause()
    {
        if (videoPlayer.isPlaying)
            videoPlayer.Pause();
        else
            videoPlayer.Play();

    }

}

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

public class NewBehaviourScript : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void LoadOnClick (int sceneIndex)
    {
        SceneManager.LoadScene(sceneIndex);
    }

}

 

Expert Solution
Step 1: Define as whole code explanation

The first script can be defined in such a way that it controls 2D character motion, such as leaping, dashing, and wall jumping, even as dealing with consumer input and managing movement parameters.

The second script can be defined in such a way that it lets in for video playback manipulation in unity, such as playing and pausing a certain video clip using the VideoPlayer component.

The third script can be defined in such a way that it offers a simple functionality to load a brand new scene in unity based on a specified scene index.

steps

Step by step

Solved in 5 steps

Blurred answer
Knowledge Booster
Top down approach design
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.
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