using UnityEngine;
public class DynamicCircle : MonoBehaviour {
public SpriteRenderer spriteRenderer;
[Min(1)] public int textureWidth = 100;
[Min(1)] public int textureHeight = 100;
public Color defaultColor = Color.white;
private Texture2D _circleTexture;
private void Start() {
CreateCircleTexture();
}
private void CreateCircleTexture() {
_circleTexture = new Texture2D(textureWidth, textureHeight);
var center = new Vector2(textureWidth / 2, textureHeight / 2);
var radius = textureWidth / 2;
for (int y = 0; y < _circleTexture.height; y++) {
for (int x = 0; x < _circleTexture.width; x++) {
float distanceToCenter = Vector2.Distance(new Vector2(x, y), center);
if (distanceToCenter <= radius) {
_circleTexture.SetPixel(x, y, defaultColor);
} else {
_circleTexture.SetPixel(x, y, Color.clear);
}
}
}
_circleTexture.Apply();
spriteRenderer.sprite = Sprite.Create(_circleTexture, new Rect(0.0f, 0.0f, textureWidth, textureHeight), new Vector2(0.5f, 0.5f), 100.0f);
}
}
if (_rigidbody.velocity.y >= 0) // вот тут, '_rigidbody'
{
gameObject.GetComponent<SpriteRenderer>().sprite = _raisingSprite;
}
else
{
gameObject.GetComponent<SpriteRenderer>().sprite = _fallSprite;
}
// вместо
public static List<Vector2> colliderPositions;
// напишите
public static List<Vector2> colliderPositions = new List<Vector2>();
if (hitInfo.collider == null) {
// то же как в блоке else
} else if (hitInfo.collider.CompareTag("Mirror")) {
// ... ну и так далее
// поле класса
public LayerMask playerLayer;
// метод из примера
RaycastHit2D hitInfo = Physics2D.Raycast(ray2D.origin, ray2D.direction, 10, playerLayer);
var methods = assembly
.GetTypes()
.SelectMany(t => t.GetMethods())
.Where(m => m.GetCustomAttributes().OfType<UpdateHandleAttribute>()
.Any(v => (v.GetType().GetProperty("Data").GetValue(v).ToString() == data ||
v.GetType().GetProperty("Data").GetValue(v).ToString() == "*")
&& v.GetType().GetProperty("State").GetValue(v).ToString() == state.Id.ToString()))
.Concat(assembly.GetTypes()
.SelectMany(t => t.GetMethods())
.Where(m => m.GetCustomAttributes().OfType<AnotherAttribute>().Any()));
Instantiate(bl_ParticalBlood, transform.position + new Vector3(horizontalInput, verticalInput, 0), Quaternion.identity);
Instantiate(bl_ParticalBlood, transform.position + new Vector3(horizontalInput, verticalInput, 0), Quaternion.identity, transform);
.GetComponent<Image>();
public int healthCurrent;
public void OnHealthChanged(int healthDelta)
healthCurrent -= healthDelta;
// update health bar
if (healthCurrent <= 0) {
// death
}
}
public int healthCurrent;
public void OnHealthChanged(int healthDelta)
if (healthCurrent > 0) {
healthCurrent -= healthDelta;
// update health bar
if (healthCurrent < 0) {
// death
}
}
}
public int healthCurrent;
public int healthMaximum;
public void OnHealthChanged(int healthDelta)
healthCurrent = Mathf.Clamp(healthCurrent - healthDelta, 0, healthMaximum);
// update health bar
if (healthCurrent == 0) {
// death
}
}