public class CameraLight : MonoBehaviour
{
[SerializeField] private Camera _camera;
[SerializeField] private Light _light;
void OnEnable()
{
RenderPipelineManager.beginCameraRendering += OnBeginCameraRendering;
RenderPipelineManager.endCameraRendering += OnEndCameraRendering;
}
void OnDisable()
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
RenderPipelineManager.endCameraRendering -= OnEndCameraRendering;
}
void OnBeginCameraRendering(ScriptableRenderContext context, Camera cam)
{
if (cam == _camera)
{
_light.enabled = false;
}
}
void OnEndCameraRendering(ScriptableRenderContext context, Camera cam)
{
if (cam == _camera)
{
_light.enabled = true;
}
}
}
carInput.UI.Move.started += ctx => OnMovePressed(ctx.ReadValue<Vector2>().normalized);
public void Update()
{
GetInvokeInput();
}
private void GetInvokeInput()
{
_inputDir = _carInput.UI.Move.ReadValue<Vector2>();
InputPressed?.Invoke(_inputDir);
}
_height = _collider.bounds.size.y / 2;
Vector3 buildPos = new Vector3(_buildScheme.ViewPosition().x, _buildScheme.ViewPosition().y + _height, _buildScheme.ViewPosition().z);
if (gameObject.activeSelf)
transform.position = buildPos;
using UnityEngine;
public class ObjectSpawner : MonoBehaviour
{
public GameObject firstObjectPrefab;
public GameObject secondObjectPrefab;
public GameObject thirdObjectPrefab;
public GameObject bombObjectPrefab;
private Vector2 firstPos;
private Vector2 secondPos;
private Vector2 thirdPos;
private Vector2 bombPos;
private void Start()
{
SpawnObjects();
}
private void SpawnObjects()
{
bool validPositions = false;
while (!validPositions)
{
// Generate random positions for all objects
float angle = Random.Range(0f, Mathf.PI * 2f);
float distanceFromCenter = Random.Range(0f, 200f);
firstPos = new Vector2(Mathf.Cos(angle) * distanceFromCenter, Mathf.Sin(angle) * distanceFromCenter);
angle = Random.Range(0f, Mathf.PI * 2f);
distanceFromCenter = Random.Range(0f, 200f);
secondPos = new Vector2(Mathf.Cos(angle) * distanceFromCenter, Mathf.Sin(angle) * distanceFromCenter);
angle = Random.Range(0f, Mathf.PI * 2f);
distanceFromCenter = Random.Range(0f, 200f);
thirdPos = new Vector2(Mathf.Cos(angle) * distanceFromCenter, Mathf.Sin(angle) * distanceFromCenter);
angle = Random.Range(0f, Mathf.PI * 2f);
distanceFromCenter = Random.Range(0f, 256f);
bombPos = new Vector2(Mathf.Cos(angle) * distanceFromCenter, Mathf.Sin(angle) * distanceFromCenter);
// Check if all positions are valid
if (Vector2.Distance(firstPos, secondPos) >= 200f &&
Vector2.Distance(secondPos, thirdPos) >= 200f &&
Vector2.Distance(thirdPos, firstPos) >= 200f &&
Vector2.Distance(firstPos, bombPos) >= 256f &&
Vector2.Distance(secondPos, bombPos) >= 256f &&
Vector2.Distance(thirdPos, bombPos) >= 256f)
{
validPositions = true;
}
}
// Spawn objects at the generated positions
Instantiate(firstObjectPrefab, firstPos, Quaternion.identity);
Instantiate(secondObjectPrefab, secondPos, Quaternion.identity);
Instantiate(thirdObjectPrefab, thirdPos, Quaternion.identity);
Instantiate(bombObjectPrefab, bombPos, Quaternion.identity);
}
}
rayShootPos = playerObject.transform.position - transform.position;
hitShoot = Physics2D.Raycast(transform.position, rayShootPos, shootDistance);
if (hitShoot.collider != null)
{
Debug.Log(hitShoot.collider.gameObject.name);
if (hitShoot.collider.gameObject.name == "Player")
{
Debug.Log("Player Dead!");
needToShoot = true;
}
else
{
needToShoot = false;
}
}
else
{
needToShoot = false;
}
float moveInputY = Input.GetAxis("Vertical");
if (moveInputY > 0)
{
Vector2 mousePosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 newPos = Vector2.MoveTowards(rigidbody2D.position, mousePosition, Time.fixedDeltaTime * shipSpeed);
rigidbody2D.MovePosition(newPos);
}
private IEnumerator SpawnPoints()
{
while(true)
{
float randomX = Random.Range(leftDown.position.x, rightDown.position.x);
float randomY = Random.Range(leftDown.position.y, leftUP.position.y);
Instantiate(prefab, new Vector3(randomX, randomY, 0), Quaternion.identity);
yield return new WaitForSeconds(1f);
}
}