ObjectType.Tome - robblofield/TomeboundDocs GitHub Wiki

MovementSystem.GridBasedMovement1

Author: Youngju Yun
Last Updated: 21/11/2023

Overview

This script holds its floor ID and the transform of both wizards. It forms part of the "ObjectType".

Dependencies

  • Gate.cs
  • GameManager.cs

Contents

  • Breakdown of code
    • Variables
    • SetDistanceBetweenX()
    • SetDistanceBetweenY()
  • Full Code Reference

Breakdown of Code

Variables

    public Transform WizX, WizY;
    public Vector3 WizXDistance, WizYDistance;
    public bool isWizXHolding, isWizYHolding;
    private GameManager gameManager;
    [Range(0,2)] public int id;

public Transform WizX, WizY: A global reference to transforms of the Wizard X and Wizard Y.

public Vector3 WizXDistance, WizYDistance: They are the distance between the Tome, Wizard X, and Wizard Y.

public bool isWizXHolding, isWizYHolding: A boolean to set true when any Wizards are grabbing the Tome.

private GameManager gameManager: A standard reference to the GameManager.cs.

[Range(0,2)] public int id: This integer represents the ID of the floor the Tome is currently at. It is Incremented when the Gate is activated and transports the Tome over the next floor.

SetDistanceBetweenX()

    public void SetDistanceBetweenWizX(Transform trans){
        WizX = trans;
        WizXDistance = transform.position - WizX.position;
        if(gameManager.invertTeleportation){
            WizXDistance = new Vector3(-WizXDistance.x, WizXDistance.y, -WizXDistance.z);
        }
        isWizXHolding = true;
    }

A function that is called when Wizard X grabs the Tome and it finds the distance between the Tome and Wizard X.

SetDistanceBetweenY()

    public void SetDistanceBetweenWizY(Transform trans){
        WizY = trans;
        WizYDistance = transform.position - WizY.position;
        if(gameManager.invertTeleportation){
            WizYDistance = new Vector3(-WizYDistance.x, WizYDistance.y, -WizYDistance.z);
        }
        isWizYHolding = true;
    }

Basically the same function as SetDistanceBetweenWizX, but for the Wizard Y.

Full Code Reference

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

public class Tome : MonoBehaviour
{
    public Transform WizX, WizY;
    public Vector3 WizXDistance, WizYDistance;
    public bool isWizXHolding, isWizYHolding;
    private GameManager gameManager;
    [Range(0,2)] public int id;

    public void Start(){
        gameManager = GameObject.FindObjectOfType<GameManager>().GetComponent<GameManager>();
    }
    public void SetDistanceBetweenWizX(Transform trans){
        WizX = trans;
        WizXDistance = transform.position - WizX.position;
        if(gameManager.invertTeleportation){
            WizXDistance = new Vector3(-WizXDistance.x, WizXDistance.y, -WizXDistance.z);
        }
        isWizXHolding = true;
    }

    public void SetDistanceBetweenWizY(Transform trans){
        WizY = trans;
        WizYDistance = transform.position - WizY.position;
        if(gameManager.invertTeleportation){
            WizYDistance = new Vector3(-WizYDistance.x, WizYDistance.y, -WizYDistance.z);
        }
        isWizYHolding = true;
    }
}