- Home /
how do I make a Object getcomponent and call a function
So I've been trying to make a script call a function from another gameobject but I've been getting an error about object not being able to work with getcomponent and I don't know whats going on. ourObject object = getcomponent().Damage2(); I've been trying other forum pages for this issue but all so far haven't been able to fix the issue. So if someone could experiment and help me that would be great! Thanks.
Answer by JackhammerGaming · Apr 14, 2020 at 06:58 AM
@CallofZON You have't specified what Component you need to access like whether you want to access transform or rigidbody etc. seeing your code i think it's a damage script so code would be something like
gameObject.GetComponent<Damage_Script> ().Damage2() ;
you can directly call out a function without storing components if you tell me exact name of script i could help you out, in the above script instead of Damage_Script put your script's name.