Skip to content

Instantly share code, notes, and snippets.

@DmitriyProkopyev
Last active June 23, 2024 13:35
Show Gist options
  • Save DmitriyProkopyev/2f715ef5ccc7f50f0790353dba03d0b6 to your computer and use it in GitHub Desktop.
Save DmitriyProkopyev/2f715ef5ccc7f50f0790353dba03d0b6 to your computer and use it in GitHub Desktop.
Code Style Task. Проведите рефакторинг кода, исправьте все ошибки в именовании и форматировании так, чтобы не изменить принцип работы кода. Учтите, что ошибки допущены не только в именовании и форматировании, но и в нарушении общепринятых стандартов и неоптимальной реализации некоторых механик. После рефакторинга должны получиться краткие, оптим…
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GoPlaces : MonoBehaviour
{
public float _float;
public Transform AllPlacespoint;
Transform[] arrayPlaces;
private int NumberOfPlaceInArrayPlaces;
void Start() {
arrayPlaces = new Transform[AllPlacespoint.childCount];
for (int abcd = 0; abcd < AllPlacespoint.childCount; abcd++)
arrayPlaces[abcd] = AllPlacespoint.GetChild(abcd).GetComponent<Transform>();
}
// Update is called once per frame
public void Update()
{
var _pointByNumberInArray= arrayPlaces[NumberOfPlaceInArrayPlaces];
transform.position = Vector3.MoveTowards(transform.position , _pointByNumberInArray.position, _float * Time.deltaTime);
if (transform.position == _pointByNumberInArray.position) NextPlaceTakerLogic();
}
public Vector3 NextPlaceTakerLogic(){
NumberOfPlaceInArrayPlaces++;
if (NumberOfPlaceInArrayPlaces == arrayPlaces.Length)
NumberOfPlaceInArrayPlaces = 0;
var thisPointVector = arrayPlaces[NumberOfPlaceInArrayPlaces].transform.position;
transform.forward = thisPointVector - transform.position;
return thisPointVector;
}
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(Rigidbody))]
public class InstantiateBulletsShooting : MonoBehaviour
{
[SerializeField] public float number;
[SerializeField] GameObject _prefab;
public Transform ObjectToShoot;
[SerializeField] float _timeWaitShooting;
// Start is called before the first frame update
void Start() {
StartCoroutine(_shootingWorker());
}
IEnumerator _shootingWorker()
{
bool isWork = enabled;
while (isWork){
var _vector3direction = (ObjectToShoot.position - transform.position).normalized;
var NewBullet = Instantiate(_prefab, transform.position + _vector3direction, Quaternion.identity);
NewBullet.GetComponent<Rigidbody>().transform.up = _vector3direction;
NewBullet.GetComponent<Rigidbody>().velocity = _vector3direction * number;
yield return new WaitForSeconds(_timeWaitShooting);
}
}
public void Update(){
// Update is called once per frame
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment