@yyakovlev0
я супер

Xотел сделать задержку но не работает canshoot почему?

проблема :мне нужно чтобы после того как игрок выстрелил canshoot был false а далее через 3 сек был тру
но оно так не работает

Скрипт тут
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.Events;



public class hero : MonoBehaviour
{

    
    Rigidbody2D rb;
    Animator anim;
    
    float run;
    public bool whenlook;
    public GameObject Gun1;
    public GameObject Hand1;
    public GameObject Hand2;
   
    public static bool jump;
    public GameObject Grass;
    
    public GameObject bulleft1;
    public GameObject bullright1;
    public GameObject Grass2;
    public GameObject Grass3;
    public bool canshoot = true;
    public float timeBetweenFires = 38f;

    private float timeTilNextFire = 0.0f;













    void Start()
    {
        
        
        
        

        
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
        

}
    



    void Update()
    {

        if (canshoot == false)
        {
            if (Time.time > timeBetweenFires)
            {
                canshoot = true;
            }
                
        }
            
        
        












        rb.velocity = new Vector2(run, rb.velocity.y);
        
    }
    public void rightArrow()
    {
        whenlook = true;
        Flip();
        run = 7f;
        anim.SetInteger("anim", 2);
    }
    public void left()
    {
        whenlook = false;
        Flip();
        run = -7;
        anim.SetInteger("anim", 2);
    }
    public void stop()
    {
        run = 0;
        anim.SetInteger("anim", 1);
    }
    public void jump1()
    {
        if (jump == false)
        {
            jump = true;
            rb.AddForce(transform.up * 18, ForceMode2D.Impulse);
        }
    }
    public void attack()
    {
        if (canshoot == true)
        {

            
            if (whenlook == true)
            {
                GameObject gameObject = Instantiate(bullright1, new Vector3(transform.position.x + 1.0f, transform.position.y + 0.00f), Quaternion.identity) as GameObject;
                
            }
            if (whenlook != true)
            {
                GameObject gameObject = Instantiate(bulleft1, new Vector3(transform.position.x - 1.0f, transform.position.y + 0.00f), Quaternion.identity) as GameObject;
                
            }
            canshoot = false;
        }    
            

        
    }



    void Flip()
    {
        if (whenlook == false)
        {

            transform.localRotation = Quaternion.Euler(0, 0, 0);
        }
        if (whenlook == true)
        {

            transform.localRotation = Quaternion.Euler(0, 180, 0);
        }

    }
     void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Grass")
            jump = false;
    }

     
}
  • Вопрос задан
  • 70 просмотров
Пригласить эксперта
Ответы на вопрос 1
MrMureno
@MrMureno Куратор тега Unity
VR for all
по сути дела - нигде не видно у вас таимера.
почитайте что возвращает Time.time и тогда поймете, что вы там сравниваете с тремя секундами.

в остальном вроде бегло глянув - принцип рабочий у вас и правильный.
поставить флаг -> запустить таимер если флаг стоит-> по таимеру сбросить флаг и остановится таимер)
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы