- Home /
Converting JavaScript to C#
//On All The Possible Targets var myPlayer:Transform; //Set this in Start() with GameObject.FindObjectWithTag("Player");
function OnMouseUpAsButton() { //myPlayer is the one targeting Get the script responsible for target attacks //target would be the one you lock onto
myPlayer.GetComponent(PlayersTargetAttackScript).target=transform;
} Then just add the var target on your players "PlayersTargetAttackScript" and say
if(target!=null)AttackTarget(); //or whatever
How would i program this in C#
Answer by Julien-Lynge · Mar 17, 2012 at 06:33 PM
There are lots of resources out there explaining how to convert between JS and C#. Start with this page:
http://fragileearthstudios.com/2011/10/18/unity-converting-between-c-and-javascript-2/
And try google searches along the lines of 'unity convert between JS and C#." Also check around on this site - this is a question that has been asked and answered numerous times.
Answer by GC1983 · Mar 17, 2012 at 06:45 PM
What you have here isnt much different in C#. Just change:
function OnMouseUpAsButton() to void OnMouseUpAsButton().
And referencing a component in C# is:
myPlayer.GetComponenet<PlayersTargetAttackScript>();
The rest would be the same as in JS.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
In the need of the light of a genius ! 2 Answers
[C#] AI Behaviour in spherical way like RESOGUN based on Rigidbodies. 1 Answer
Procedural floor plan/room layout (2D) 0 Answers