UNITY: ADD SOUND OR AUDIO TO YOUR GAME

 Code used in video:

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

public class Player : MonoBehaviour {
  Rigidbody2D playerRB;
  BoxCollider2D playerCollider;

  float moveSpeeed = 200.0f;
  float direction;

  float jumpHeight = 5.0f;
  LayerMask groundLayer;
  bool playerIsGrounded = false;
  bool doubleJumped = false;

  AudioSource[] audioSources;
  // Use this for initialization
  void Start () {
    playerRB = GetComponent<Rigidbody2D>();
    playerCollider = GetComponent<BoxCollider2D>();
    groundLayer = LayerMask.GetMask("Ground");
    audioSources = GetComponents<AudioSource>();
  }

  private void FixedUpdate() {
    playerIsGrounded = Physics2D.IsTouchingLayers(playerCollider, groundLayer);
  }
 
  // Update is called once per frame
  void Update () {
    direction = Input.GetAxisRaw("Horizontal");
    move(direction);

    // JUMP ROUTINE
    if(playerIsGrounded){
      doubleJumped = false;
    }
    //for the first jump
    if(Input.GetKeyDown(KeyCode.Space) && playerIsGrounded){
      jump();
    }
    //for the second jump
    if(Input.GetKeyDown(KeyCode.Space) && !playerIsGrounded && !doubleJumped){
      jump();
      doubleJumped = true;
    }
    // END JUMP ROUTINE

    if(transform.position.y < -3){
      //game over
      SceneManager.LoadScene("GameOverScene");
    }

  }

  void move(float direction){
    float velocity = direction * moveSpeeed * Time.deltaTime;
    playerRB.velocity = new Vector2(velocity,playerRB.velocity.y);
  }
  void jump(){
    playerRB.velocity = new Vector2(playerRB.velocity.x, jumpHeight);
    audioSources[0].Play();
  }

  private void OnCollisionEnter2D(Collision2D otherObject) {
    if(otherObject.transform.tag.Equals("Obstacle")){
      PlayAudio(1);
    }else if(otherObject.transform.tag.Equals("Enemy")) {
      PlayAudio(2);
    }
  }

  private void OnTriggerEnter2D(Collider2D otherObject) {
    if(otherObject.transform.tag.Equals("Enemy")){
      Debug.Log("Game Over!");
    }
  }

  void PlayAudio(int index){
    StopAllAudio();
    audioSources[index].Play();
  }

  void StopAllAudio(){
    for(int i=0;i<audioSources.Length;i++){
      if(audioSources[i].isPlaying){
        audioSources[i].Stop();
      }
    }
  }


}







SEND EMAIL ATTACHMENTS AND OTHER OPTIONS - GOOGLE APPS SCRIPT

 Code as seen in the video:

Code.gs

function doGet(e) {
  var page = e.parameter.page || "index";

  switch(page){
    case "about":
      // return HtmlService.createHtmlOutputFromFile("About");
      var template = HtmlService.createTemplateFromFile("About");
      template.username = "Bea Ysabel";
      return template.evaluate();
    case "contact":
      return HtmlService.createHtmlOutputFromFile("ContactUs");
    default:
      //return HtmlService.createHtmlOutputFromFile("Index");
      return HtmlService.createTemplateFromFile("Index").evaluate();
  }
 
}

function getScriptUrl(){
  return ScriptApp.getService().getUrl();
}

function getGreetings(){
  return "Greetings from the server!";
}

function include(filename){
 return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

function sendEmail(to, cc, bcc, subject, body, files){
  try{
    //convert the files to blob
    var attachments = files.map(base64String => {
      var mimeType = base64String.match(/data:(.*?);base64,/)[1];
      var base64Data = base64String.split(',')[1];
      var blob = Utilities.newBlob(Utilities.base64Decode(base64Data), mimeType);
      return blob;
    })

    MailApp.sendEmail(
      {
        to: to,
        cc:cc,
        bcc:bcc,
        subject: subject,
        htmlBody: body,
        attachments: attachments
      }
    );
    return "Email sent Successfully!";
  }catch(err){
    return `Something went wrong! ${err}`;
  }
}

Scripts.html
  <script>
    function openModal(){
      const myModal = new bootstrap.Modal(document.getElementById('emailModal'), {
        keyboard: false,
        backdrop:"static"
      });
      myModal.show();
    }

    async function sendMail(){
      const to = document.getElementById("to").value;
      const cc = document.getElementById("cc").value;
      const bcc = document.getElementById("bcc").value;
      const subject = document.getElementById("subject").value;
      var body = document.getElementById("body").value;

      body = `
        <h1>${body}</h1>
        <ul>
          <li>List #1</li>
          <li>List #2</li>
          <li>List #3</li>
          <li>List #4</li>
        </ul>
      `;

      var files = document.getElementById("files").files;

      //convert files to base64 format
      var attachments = [];
      for(var i=0; i < files.length; i++){
        var base64String = await readFileAsBase64(files[i]);
        attachments.push(base64String);
      }
     

      google.script.run.withSuccessHandler(
        function(response){
          document.getElementById("messageDiv").innerText = response;
        }
      ).sendEmail(to,cc,bcc,subject,body,attachments);
    }

    async function readFileAsBase64(file) {
      //from the web
      return new Promise((resolve, reject) => {
        var reader = new FileReader();
        reader.onload = function(e) {
          resolve(e.target.result);
        };
        reader.onerror = function(e) {
          reject(e);
        };
        reader.readAsDataURL(file);
      });
    }

    function buttonClicked(){
      google.script.run.withSuccessHandler(function(response){
        var msgDiv = document.getElementById("messageDiv");
        msgDiv.innerText = response;
      }).getGreetings();
    }

    function updateLinks(linksList){
      google.script.run.withSuccessHandler(
        function(url){
          linksList.forEach(function(link){
            document.getElementById(link.id).href = `${url}?page=${link.param}`;
          })
        }
      ).getScriptUrl();
    }

    document.addEventListener("DOMContentLoaded",
      function(){
        const links = [
          {id:"aboutLink", param:"about"},
          {id:"contactLink", param:"contact"}
        ]
        updateLinks(links);
      }
    );
  </script>

Modal.html

  <!-- MODAL -->
  <div class="modal fade" id="emailModal" role="modal" >
    <div class="modal-dialog modal-md">
      <div class="modal-content">
        <div class="modal-header text-white" style="background-color:#006400">
          <h5 class="modal-title" id="modalTitle">Send Email</h5>
          <button type="button" class="btn-close btn-primary" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body" id="modalBody">
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="example@myemail.com" id="to">
          </div>
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="cc@myemail.com" id="cc"/>
          </div>
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="bcc@myemail.com" id="bcc"/>
          </div>
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="Subject" id="subject"/>
          </div>
          <div class="row m-1">
            <textarea placeholder="Body" id="body" rows="5"class="form-control"/></textarea>
          </div>
          <div class="row m-1">
            <input type="file" id="files" multiple /></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          <button type="button" id="btnSendMail" class="btn btn-primary" onclick='sendMail()'>Send</button>
        </div>
      </div>
    </div>
  </div>


SEND EMAIL USING MAILAPP CLASS - GOOGLE APPS SCRIPT

 Code used in the video:

Index.html

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" >


    <?!= include("Styles")   ?>
    <?!= include("Scripts")   ?>


  </head>
  <body>
    <img src="https://drive.google.com/thumbnail?id=1WkCDv7FBdfXffLmHQNOoP7C5hu5IVehS" alt="my image from google drive"/>
    <img src="https://imagizer.imageshack.com/v2/640x480q70/922/zzcOPK.jpg" alt="My Bike" width="300" height="200"/>
    <h1 class="pula">HELLO GOOGLE APPS SCRIPT WEB APPS!</h1>
    <h1 class="berde">Please be good to me...</h1>
    <h2>Hello World!</h2>
    <button class="btn btn-primary" onclick="buttonClicked()">Click Me</button>
    <div id="messageDiv"></div>
    <a href="#" id="aboutLink">About</a>
    <a href="#" id="contactLink">Contact Us</a>

    <button class="btn btn-primary" onclick="openModal()">Send Email</button>


    <?!= include("Modal"); ?>



  </body>
</html>


Scripts.html

  <script>
    function openModal(){
      const myModal = new bootstrap.Modal(document.getElementById('emailModal'), {
        keyboard: false,
        backdrop:"static"
      });
      myModal.show();
    }

    function sendMail(){
      const recepient = document.getElementById("to").value;
      const subject = document.getElementById("body").value;
      const body = document.getElementById("subject").value;

      google.script.run.withSuccessHandler(
        function(response){
          document.getElementById("messageDiv").innerText = response;
        }
      ).sendEmail(recepient, subject, body);
    }


    function buttonClicked(){
      google.script.run.withSuccessHandler(function(response){
        var msgDiv = document.getElementById("messageDiv");
        msgDiv.innerText = response;
      }).getGreetings();
    }

    function updateLinks(linksList){
      google.script.run.withSuccessHandler(
        function(url){
          linksList.forEach(function(link){
            document.getElementById(link.id).href = `${url}?page=${link.param}`;
          })
        }
      ).getScriptUrl();
    }

    document.addEventListener("DOMContentLoaded",
      function(){
        const links = [
          {id:"aboutLink", param:"about"},
          {id:"contactLink", param:"contact"}
        ]
        updateLinks(links);
      }
    );
  </script>

Modal.html

 

  <!-- MODAL -->
  <div class="modal fade" id="emailModal" role="modal" >
    <div class="modal-dialog modal-md">
      <div class="modal-content">
        <div class="modal-header text-white" style="background-color:#006400">
          <h5 class="modal-title" id="modalTitle">Send Email</h5>
          <button type="button" class="btn-close btn-primary" data-bs-dismiss="modal" aria-label="Close"></button>
        </div>
        <div class="modal-body" id="modalBody">
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="example@myemail.com" id="to"/>
          </div>
          <div class="row m-1">
            <input type="text" class="form-control" placeholder="Subject" id="subject"/>
          </div>
          <div class="row m-1">
            <textarea placeholder="Body" id="body" rows="5"class="form-control" /></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
          <button type="button" id="btnSendMail" class="btn btn-primary" onclick='sendMail()'>Send</button>
        </div>
      </div>
    </div>
  </div>

Code.gs

 

function doGet(e) {
  var page = e.parameter.page || "index";

  switch(page){
    case "about":
      // return HtmlService.createHtmlOutputFromFile("About");
      var template = HtmlService.createTemplateFromFile("About");
      template.username = "Bea Ysabel";
      return template.evaluate();
    case "contact":
      return HtmlService.createHtmlOutputFromFile("ContactUs");
    default:
      //return HtmlService.createHtmlOutputFromFile("Index");
      return HtmlService.createTemplateFromFile("Index").evaluate();
  }
 
}

function getScriptUrl(){
  return ScriptApp.getService().getUrl();
}

function getGreetings(){
  return "Greetings from the server!";
}

function include(filename){
 return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

function sendEmail(emailRecepient, emailSubject, emailBody){
  try{
    MailApp.sendEmail(
      {
        to: emailRecepient,
        subject: emailSubject,
        body: emailBody
      }
    );
    return "Email sent Successfully!";
  }catch(err){
    return `Something went wrong! ${err}`;
  }
}


 




WORKING WITH HEADER-DETAIL FORM IN VANILLA JAVASCRIPT WITH API/PHP AND MYSQL

invoice.html < html lang = "en" >   < head >     < meta charset = "UTF-8" />     < meta name = ...