Player.cs 1.16 KB
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Player : MonoBehaviour
{
    public float speed = 5.0f;
    public SerialHandler serialHandler;

    void Update () {
            
            if (Input.GetKey(KeyCode.RightArrow)){
                transform.position += Vector3.right * speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.LeftArrow)){
                transform.position += Vector3.left* speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.UpArrow)){
                transform.position += Vector3.forward * speed * Time.deltaTime;
            }
            if (Input.GetKey(KeyCode.DownArrow)){
                transform.position += Vector3.back* speed * Time.deltaTime;
            }
        }

    private void OnTriggerEnter(Collider other) {
        if (other.name == "ColdSphere") serialHandler.Write("s");
        else if (other.name == "HotSphere") serialHandler.Write("f");
    }

    private void OnTriggerExit(Collider other) {
        if (other.name == "ColdSphere") serialHandler.Write("a");
        else if (other.name == "HotSphere") serialHandler.Write("d");
    }
}