Lesson14

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

public class AudioManager : MonoBehaviour
{

    private GameObject player;
    private AudioSource audioSE;
    public AudioClip sound01;
    private bool killSEflag = true;

    void Start ()
    {
        audioSE = gameObject.AddComponent<AudioSource>();
	}
	
	void Update ()
    {
        player = GameObject.FindWithTag("Player");
        if (player == null && killSEflag == true)
        {
            audioSE.PlayOneShot(sound01);
            killSEflag = false;
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Bounce : MonoBehaviour
{

    public float bounce = 10.0f;

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Player")
        {
            Vector3 norm = other.contacts[0].normal;
            Vector3 vel = other.rigidbody.velocity.normalized;
            vel += new Vector3(-norm.x * 2, 0f, -norm.z * 2);
            other.rigidbody.AddForce(vel * bounce, ForceMode.Impulse);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerController : MonoBehaviour
{

    public float speed = 12.0f;
    public float brake = 0.5f;
    private Rigidbody rB;
    private Vector3 rbVelo;

    public Text goalText;
    public bool goalOn;
    public ParticleSystem explosion;
    public Text failText;
    private Vector3 height;
    public float jumpForce = 20.0f;
    public float turboForce = 2.0f;

    void Start ()
    {
        rB = GetComponent<Rigidbody>();
        goalText.enabled = false;
        goalOn = false;
        failText.enabled = false;
	}
	
	void Update ()
    {
        if (goalOn == false)
        {
            rbVelo = Vector3.zero;
            float x = Input.GetAxis("Horizontal");
            float z = Input.GetAxis("Vertical");
            rbVelo = rB.velocity;
            rB.AddForce(x * speed - rbVelo.x * brake, 0, z * speed - rbVelo.z * brake, ForceMode.Impulse);
        }

        height = this.GetComponent<Transform>().position;
        if (height.y <= -3.0f)
        {
            explosion.transform.position = this.transform.position;
            explosion.Play();
            this.gameObject.SetActive(false);
        }
	}

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Goal")
        {
            other.gameObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 1);
            rB.AddForce(-rbVelo.x * 0.8f, 0, -rbVelo.z * 0.8f, ForceMode.Impulse);
            goalText.enabled = true;
            goalOn = true;
        }

        if (other.gameObject.tag == "Jump")
        {
            rB.AddForce(0, jumpForce, 0, ForceMode.Impulse);
        }
    }

    void OnTriggerStay(Collider other)
    {
        if (other.gameObject.tag == "Turbo")
        {
            Vector3 vel = rB.velocity;
            rB.AddForce(vel.x * turboForce, 0, vel.z * turboForce, ForceMode.Impulse);
        }
    }

    void OnCollisionEnter(Collision other)
    {
        if (other.gameObject.tag == "Kill")
        {
            explosion.transform.position = this.transform.position;
            this.gameObject.SetActive(false);
            failText.enabled = true;
            explosion.Play();
        }

        if (other.gameObject.tag == "Bounce")
        {
            StartCoroutine("WaitKeyInput");
        }
    }

    IEnumerator WaitKeyInput()
    {
        this.gameObject.GetComponent<PlayerController>().enabled = false;
        yield return new WaitForSeconds(1.0f);
        this.gameObject.GetComponent<PlayerController>().enabled = true;
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerTrigger : MonoBehaviour
{

    void OnTriggerEnter(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            this.gameObject.GetComponent<Renderer>().material.color = new Color(1, 0, 0, 1);
        }
    }

    void OnTriggerExit(Collider other)
    {
        if (other.gameObject.tag == "Player")
        {
            this.gameObject.GetComponent<Renderer>().material.color = new Color(0, 0, 1, 1);
        }
    }
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class Replay : MonoBehaviour
{

    public void ReplayGame()
    {
        SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }
}
テトリス

次の記事

60.#3