- Home /
Question by
Sayden96 · Jan 10, 2021 at 04:53 PM ·
scripting problemgameobjectfloat
Change Parameters to script with other script
I have a boss with two script in different parts. When i put the health in 10 i need to change the velocity of the boss to 4. I write the script but doesn't work.
The first script:
public class VitalPoint : MonoBehaviour
{
public int health = 12;
private gameMaster gm;
private UnityEngine.Object explosionRef;
public GameObject Hiedra;
public bool isHurt = false;
private HiedraScript ChangeVelocity;
void Start()
{
gm = GameObject.FindGameObjectWithTag("GameMaster").GetComponent<gameMaster>();
explosionRef = Resources.Load("Explosion");
ChangeVelocity = gameObject.GetComponent<HiedraScript>();
}
void Update()
{
}
void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Bullet"))
{
Destroy(collision.gameObject);
health--;
Hiedra.GetComponent<Animation>().Play("Player_RedFlash");
if (health <= 10)
MovesFaster();
isHurt = true;
if (health <= 0)
KillSelf();
}
if (health <= 0)
{
gm.points += 20;
}
}
private void MovesFaster()
{
ChangeVelocity.moveSpeed = 4f;
}
private void KillSelf()
{
GameObject explosion = (GameObject)Instantiate(explosionRef);
explosion.transform.position = new Vector3(transform.position.x, transform.position.y + 2f, transform.position.z);
Destroy(GameObject.Find("Hiedra"));
}
}
The parameter of boss script:
public float moveSpeed = 1f;
Comment
Your answer
Follow this Question
Related Questions
Spawn an object with additional parameter 1 Answer
Unity 3D: How to make the gameobject speed increase continuously on tapping quickly? 1 Answer
Script wont let me drag and drop GameObject Of UI Menu into it? 1 Answer
How to make an object invisible before it is triggered to show? 2 Answers
Creating a GameObject variable without instantiating it? 1 Answer