Skip to content

Instantly share code, notes, and snippets.

@Avet1k
Forked from DmitriyProkopyev/BadExample.cs
Last active November 26, 2023 16:19
Show Gist options
  • Save Avet1k/7e58a3bfe00fd8d8872501700c2f5549 to your computer and use it in GitHub Desktop.
Save Avet1k/7e58a3bfe00fd8d8872501700c2f5549 to your computer and use it in GitHub Desktop.
Code Style Task. Проведите рефакторинг кода, исправьте все ошибки в именовании и форматировании так, чтобы не изменить принцип работы кода
using UnityEngine;
public class WaypointMovement : MonoBehaviour
{
private Transform _path;
private Transform[] _points;
private int _currentPoint;
private float _speed;
private void Start()
{
_points = new Transform[_path.childCount];
for (int i = 0; i < _path.childCount; i++)
_points[i] = _path.GetChild(i).GetComponent<Transform>();
}
private void Update()
{
Transform target = _points[_currentPoint];
transform.position = Vector3.MoveTowards(transform.position , target.position,
_speed * Time.deltaTime);
if (transform.position == target.position)
ChangeTarget();
}
private void ChangeTarget()
{
_currentPoint++;
if (_currentPoint >= _points.Length)
_currentPoint = 0;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
[RequireComponent(typeof(Rigidbody))]
public class Shooting : MonoBehaviour
{
[SerializeField] private float _speed;
[SerializeField] private float _cooldown;
[SerializeField] private GameObject _bullet;
[SerializeField] private Transform _target;
private void Start()
{
StartCoroutine(Shoot());
}
private IEnumerator Shoot()
{
bool isWork = enabled;
while (isWork)
{
Vector3 direction = (_target.position - transform.position).normalized;
GameObject newBullet = Instantiate(_bullet, transform.position + direction, Quaternion.identity);
newBullet.transform.up = direction;
newBullet.GetComponent<Rigidbody>().velocity = direction * _speed;
yield return new WaitForSeconds(_cooldown);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment