unity
unityでもしsiniがfalseならlogをだしてこのオブジェクトを消すというプログラムをつくったのですが sini == false がうまく機能しません。問題点を教えていただきたいです。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class text : MonoBehaviour
{
public teki teki;
private bool sini;
// Start is called before the first frame update
void Start()
{
this.gameObject.SetActive(true);
sini = teki.si;
sini = true;
}
// Update is called once per frame
void Update()
{
if (sini == false)
{
Debug.Log("ata");
this.gameObject.SetActive(true);
}
}
public teki teki;というのは下のものです
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class teki : MonoBehaviour
{
public string targetObjectName;
public float speed = 1;
public bool si;
GameObject targetObject;
Rigidbody2D rbody;
// Start is called before the first frame update
void Start()
{
targetObject = GameObject.Find(targetObjectName);
rbody = GetComponent<Rigidbody2D>();
rbody.gravityScale = 0;
rbody.constraints = RigidbodyConstraints2D.FreezeRotation;
Time.timeScale = 1;
si = true;
}
// Update is called once per frame
void Update()
{
}
void FixedUpdate()
{
Vector3 dir = (targetObject.transform.position - this.transform.position).normalized;
float vx = dir.x * speed;
float vy = dir.y * speed;
rbody.velocity = new Vector2(vx, vy);
}
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.gameObject.name == targetObjectName)
{
si = false;
Time.timeScale = 1;
}
}
}
0