12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class player : MonoBehaviour
- {
- [HideInInspector]
- public Animator anim;
- [Header("Скорость танка")]
- public float speed;
-
- [HideInInspector]
- public Rigidbody2D rb;
-
- [HideInInspector]
- public float moveInput;
-
- [HideInInspector]
- public bool faceRight;
-
- [HideInInspector]
- public GameObject Bullet;
-
- [HideInInspector]
- public Transform spawn;
- void Start()
- {
- rb = GetComponent<Rigidbody2D>();
- anim = GetComponent<Animator>();
- }
- void Update()
- {
- moveInput = Input.GetAxis("Horizontal");
- transform.Translate(moveInput * speed, 0, 0);
-
- if (faceRight == false && moveInput < 0)
- {
- Flip();
- }
- else if (faceRight == true && moveInput > 0)
- {
- Flip();
- }
-
- if(Input.GetMouseButtonDown(0))
- {
- StartCoroutine(DelayAttack());
- }
- }
- IEnumerator DelayAttack()
- {
- Instantiate(Bullet, spawn.position, Quaternion.identity, this.transform);
- yield return new WaitForSeconds(0.3f);
- }
- public void Flip()
- {
- faceRight = !faceRight;
- Vector3 scaler = transform.localScale;
- scaler.x *= -1;
- transform.localScale = scaler;
- }
- }
|