using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Tilemaps;
public class Box : MonoBehaviour
{
const float Gravity = -0.01f;
const float OffsetY = -0.5f;
const int StrCut = 8;
const float TAnker = 0.5f;
[SerializeField]
Tilemap tilemap;
Time60 time60;
Vector3 pos;
Vector3 checkPos = new Vector3();
Vector3 speed = new Vector3();
int index = 0; //タイル(スプライト)の番号
float dist = 0; //めり込んだ長さ
string str = ""; //テキスト表示用
bool isGround = false;
public string sText;
// Start is called before the first frame update
void Start()
{
GameObject time60Obj = GameObject.Find("Time60");
time60 = time60Obj.GetComponent();
pos = this.transform.position;
checkPos = Vector3.zero;
speed = Vector3.zero;
}
// Update is called once per frame
void Update()
{
// 1/60秒ごとに処理をするための門番
if( time60.CheckFlame() != true) return;
//現在位置を受け取る
pos = this.transform.position;
//チェックする位置を決める
checkPos = new Vector3(pos.x, pos.y + OffsetY, 0);
//=======================
//判定地点のタイル番号を抽出
//=======================
//グリッド座標に変換する
Vector3Int targetPosInt = tilemap.WorldToCell(checkPos);
//グリッド座標のスプライト情報を取得する
Sprite spr = tilemap.GetSprite(targetPosInt);
if(spr != null)
//"Terrain_"の文字を取り除く
str = spr.name.Substring( 8, spr.name.Length - 8);
else
str = "-1";
//Int型に変換
index = int.Parse(str);
//ボックスの自由落下
speed.y = speed.y + Gravity;
/
dist = 0;
if( index == 1){
dist = 1 - (checkPos.y % 1);
speed.y = 0;
}
pos = new Vector3( pos.x, pos.y + speed.y + dist, 0);
transform.position = pos;
}
}