I made a script to switch through two different camera’s for locking onto an enemy (My logic isn’t finished yet but not the point).
I first had a public variable called CinemachineVirtualCamera and referenced my gameobject with the CineMachine virtualCamera to that variable.
But it gives me this error:
Severity Code Description Project File Line Suppression State Warning CS8032 An instance of analyzer Unity.Properties.SourceGenerator.PropertyBagGenerator cannot be created from C:Program FilesUnityHubEditor2022.3.25f1EditorDataToolsUnity.SourceGeneratorsUnity.Properties.SourceGenerator.dll: Could not load file or assembly 'System.Runtime, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. Het systeem kan het opgegeven bestand niet vinden.. Assembly-CSharp C:Program FilesUnityHubEditor2022.3.25f1EditorDataToolsUnity.SourceGeneratorsUnity.Properties.SourceGenerator.dll 1 Active
but the script does exactly what I tell it to do.
But when I referenced the variable through the start method with getcomponentinchildren<CinemachinVirtualCamera>() I didnt get the error but the script didnt do what I wanted it to do
should I just ignore the warning or am I doing something wrong?
This is my whole script:
[Header("Bools")]
public bool locked;
[Header("Lock on settings")]
public LayerMask enemyLayer;
public float radius;
public float maxAngle;
//private void Start()
//{
// enemyCamera = GetComponentInChildren<CinemachineVirtualCamera>();
//}
public void Update()
{
Inputs();
PlayerLookAt();
}
void Inputs()
{
if (Input.GetKeyDown(KeyCode.Mouse1) && !locked)
{
if (enemyCamera == null)
{
print("Waarom werk jij niet");
}
enemy = CalcEnemyLock();
enemyCamera.LookAt = enemy;
SetCamera();
}
else if (Input.GetKeyDown(KeyCode.Mouse1) && locked)
{
locked = false;
SetCamera();
}
}
Transform CalcEnemyLock()
{
Collider[] nearbyEnemy = Physics.OverlapSphere(transform.position, radius, enemyLayer);
float closestAngle = maxAngle;
Transform closestTarget = null;
if(nearbyEnemy.Length <= 0)
{
return null;
}
for(int i = 0; i < nearbyEnemy.Length; i++)
{
Vector3 dir = nearbyEnemy[i].transform.position - mainCamera.transform.position;
dir.y = 0;
float angle = Vector3.Angle(mainCamera.transform.forward, dir);
if (angle < maxAngle)
{
closestTarget = nearbyEnemy[i].transform;
closestAngle = angle;
}
}
locked = true;
return closestTarget;
}
void SetCamera()
{
if (locked)
{
freeLook.Priority = 10;
enemyCamera.Priority = 20;
}
else
{
freeLook.Priority = 20;
enemyCamera.Priority = 10;
}
}
void PlayerLookAt()
{
if (locked)
{
player.LookAt(enemy);
}
else
{
player.LookAt(null);
}
}
I tried referencing it in different ways so the cinemachinevirtual camera variable wouldnt be null but the script only worked when it was null
Can Silay is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.