- Home /
Access a C# script on collison
Hey,
I want to access a C# script and change some public values in them on collison with a collider tagged "Water" By my player(Lets say that the script is called ScriptA). I'd do it myself but I'm not good with C# and the script I'm trying to change values in is in C#. I'd love if someone would give me the full thing or at least good guidelines to follow.
You give few specifics. Plus if you get your compile order correct, you should be able to write a JavaScript to make the conversion. The easiest pathway to a solution (you imply that you know JavaScript), may be to write the script in JavaScript and then attempt to convert it to C#. If you have trouble, post your attempt here.
http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html
Answer by Ejlersen · Aug 06, 2013 at 07:04 PM
Here is a hint of how to do it:
public class Example : MonoBehaviour
{
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.layer == LayerMask.NameToLayer("Water"))
{
ScriptA sa = collision.gameObject.GetComponent<ScriptA>();
if (sa != null)
sa.ChangeValuesOnHit();
}
}
}
Remember to mark your question as answered, if it works out for you :)
Your answer
