I have a scene with 2 objects in 2D named “Circle” and name “Square”.
Inside of Square, I put this script to change 2 attributes (color and gravity) of Circle object.
using UnityEngine;
public class Square : MonoBehaviour
{
GameObject circulo;
void Start()
{
circulo = GameObject.Find("Circle");
circulo.GetComponent<Rigidbody2D>().gravityScale = 0.05f;
}
void Update()
{
if (Input.GetKey(KeyCode.Space))
{
circulo.GetComponent<SpriteRenderer>().color = Color.red;
circulo.GetComponent<Rigidbody2D>().gravityScale = 0;
}
}
}
My problem is this: When I press “space key” Circle change color, but don’t change gravity (circle keeps moving to g = 0.05f).
But (and very strange), if inside of conditional, gravityScale=5, then changes ¿What’s going on?
Thank you! and I’m sorry by my english language.