скрипт:
Синтаксис:
Используется csharp
void FixedUpdate
gameObject.transform.Translate(Vector2.right * Speed * Time.deltaTime, Space.Self);
rb.MoveRotation(rb.rotation +mass * -Time.fixedDeltaTime);
RaycastHit2D hit = Physics2D.Raycast(gameObject.transform.position, gameObject.transform.right, 3f, LayerMask.GetMask("Default"));
Debug.DrawLine(transform.position, gameObject.transform.right, Color.red, 3f);
if (hit.collider.tag == "metall")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(MetallColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "wood")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(WoodColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "glass")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(GlassColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "beton")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(BetonColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "grass")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(BetonColSound, gameObject.transform.position);
Destroy(gameObject);
}
else
{
}
}
gameObject.transform.Translate(Vector2.right * Speed * Time.deltaTime, Space.Self);
rb.MoveRotation(rb.rotation +mass * -Time.fixedDeltaTime);
RaycastHit2D hit = Physics2D.Raycast(gameObject.transform.position, gameObject.transform.right, 3f, LayerMask.GetMask("Default"));
Debug.DrawLine(transform.position, gameObject.transform.right, Color.red, 3f);
if (hit.collider.tag == "metall")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(MetallColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "wood")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(WoodColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "glass")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(GlassColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "beton")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(BetonColSound, gameObject.transform.position);
Destroy(gameObject);
}
else if (hit.collider.tag == "grass")
{
print("collision raycast" + hit.collider.gameObject.name);
AudioSource.PlayClipAtPoint(BetonColSound, gameObject.transform.position);
Destroy(gameObject);
}
else
{
}
}