I want to know why I can’t make the comparison in the Chase
function of the Action
script. The specific comparison is: if (stats.creature == 0) { Debug.Log("Creature Sea Urchin"); }
In the Entity
script, stats
is a ScriptableObject that I created, and creature
is a float. The ScriptableObjectStats
I referenced in the Entity
script has creature = 0
.
The Entity
and Action
scripts are on the same object.
using Unity.Mathematics;
using System;
using UnityEngine;
namespace OnlyRule
{
public class Action : MonoBehaviour
{
//Referenciando os status
public Entity stats;
//Referenciando o Rigidbody2D
Rigidbody2D rb;
//Referenciando o estado da entidade
public string state;
//Referenciando o obj alvo
public GameObject target, target_sensor, priority_target;
public quaternion add_rotation;
public string ActionName;
void Start()
{
stats = gameObject.GetComponent<Entity>();
rb = GetComponent<Rigidbody2D>();
ActionName = stats.Name;
//Debug.Log("\nname entity: " + stats.Name + "\n speed: " + stats.speed + "\n rigidbody2D: " + stats.heavy);
}
// Update is called once per frame
void Update()
{
if(state == "idle")
{
}
if(state == "chase")
{
//Verefica se os alvo são validos antes de passar entrar no Chase
if(target_sensor != null || priority_target != null)
{
if(priority_target == null)
{
target = target_sensor;
}
else
{
target = priority_target;
}
Chase(target.transform.position);
// ok Debug.Log("target valido");
}
//Sai do estado "chase"
else
{
state = "idle";
target = null;
}
// ok Debug.Log("Rodando chase");
}
}
public void Chase(Vector3 v3)
{ //Movimentação com base na criatura
// ok Debug.Log("nome atual: " + stats.Name);
if (stats.creature == 0)
{
Debug.Log("Creature Sea Urchin");
}
/*if(stats.Name == "Sea Urchin")
{
/*if(v3.x < transform.position.x)
{
//mover-se para direita(negativo)
add_rotation = quaternion.Euler(0, 0, math.radians(transform.rotation.z) - math.radians(stats.speed));
rb.MoveRotation(add_rotation);
}
if(v3.x > transform.position.x)
{
//mover-se para esquerda(positivo)
add_rotation = quaternion.Euler(0, 0, math.radians(transform.rotation.z) + math.radians(stats.speed));
rb.MoveRotation(add_rotation);
}
float rotationSpeed = stats.speed;
// Gira o objeto no eixo Z constantemente
rb.MoveRotation(rb.rotation + rotationSpeed * Time.deltaTime);
}*/
// ok Debug.Log("nome atual: " + stats.Name);
}
}
}
using UnityEngine;
namespace OnlyRule
{
public class Entity : MonoBehaviour
{
//Status do obj
public ScriptableObjectEntityStats stats;
public InterativeOBJ item;
//Status Básicos
public float base_hp,
base_speed,
base_heavy,
base_damage,
//Status Atuais
hp,
speed,
heavy,
damage,
//Status Bônus
bonus_hp,
bonus_speed,
bonus_heavy,
bonus_damage,
creature;
public string Name;
//Referenciando o Rigidbody2D
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
//Definindo status
base_hp = stats.life;
base_speed = stats.speed;
base_heavy = stats.heavy;
base_damage = stats.damage;
creature = stats.creature;
Name = stats.name_;
UpadateStats();
Debug.Log(Name);
}
void Update()
{
}
void UpdateSatsBonus(InterativeOBJ stats_bonus)
{
if(stats_bonus == null)
{
stats_bonus = new InterativeOBJ();
}
bonus_hp = stats_bonus.life;
bonus_speed = stats_bonus.speed;
bonus_heavy = stats_bonus.heavy;
bonus_damage = stats_bonus.damage;
}
void UpadateStats()
{
hp = base_hp + bonus_hp;
speed = base_speed + bonus_speed;
heavy = base_heavy + bonus_heavy;
rb.mass = heavy;
damage = base_damage + bonus_damage;
}
}
}