- Home /
              This post has been wikified, any user with enough reputation can edit it. 
            
 
            Need help converting js to C
Hi!
original js script:
 #pragma strict
 #pragma implicit
 #pragma downcast
 
 static var destroyed:int=0;
 
 var score10:Material;
 var score30:Material;
 var score50:Material;
 var score100:Material;
 var score150:Material;
 var score200:Material;
 var score250:Material;
 var score3000:Material;
 var scoreParticle:GameObject;
 
 
 var crackSound:AudioClip;
 
 private var color:Color;
 private var object:Vector3;
 
 public var container :GameObject;
 
 
 function Update()
 {
     if (Input.GetButtonDown("Fire1")) 
     {
            var ray = GetComponent.<Camera>().ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
            var hit : RaycastHit; 
            if ( Physics.Raycast (ray, hit, 30.0) ) //if we hit something
            { 
                if(hit.rigidbody)
                { //and it is rigidbody
                   object=hit.collider.transform.position;  // hitted object's position
                   color=hit.collider.renderer.material.color; //hitted object's color
                 hit.collider.gameObject.GetComponent.<chack>().Start(); //enable hitted object's chack script,
                 audio.volume=0.7;
                 audio.PlayOneShot(crackSound); //play crackSound
                 if(destroyed <= 0 && (int.Parse(container.GetComponent(instantiate).score) >= 10))
                 { //if we clicked and don't destroyed any balls
                     var minusScore=Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) as GameObject; //instantiate scoreParticle
                     minusScore.renderer.material=score10; //give material to scoreParticle
                     minusScore.renderer.material.color = color;//give ball's color to scoreParticle
                     //scoreText.text=""+(int.Parse(scoreText.text) - 10); //minus 10 to score text
                     container.GetComponent(instantiate).score=""+(int.Parse(container.GetComponent(instantiate).score) - 30); //minus 10 to score text
                 }
             }
         }         
     }
 }
 
 
 
 
 function scoresCalculation(){
 yield WaitForSeconds (0.2);
 if(destroyed == 3){//if we destroyed 3 ball
 var score1=Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity) as GameObject; //instantiate scoreParticle
 score1.renderer.material=score30; //give material to scoreParticle
 score1.renderer.material.color = color;//give ball's color to scoreParticle
 //scoreText.text=""+(int.Parse(scoreText.text)+30); //plus 30 to score text 
 container.GetComponent(instantiate).score=""+(int.Parse(container.GetComponent(instantiate).score)+30); //plus 30 to score text 
 }
 }
Converted to C# ... fixed what i can:
 using UnityEngine;
 using System.Collections;
 
 public class clickdetecting : MonoBehaviour 
 {
 
 
 
 public static int destroyed=0;
 
 Material score10;
 Material score30;
 Material score50;
 Material score100;
 Material score150;
 Material score200;
 Material score250;
 Material score3000;
 GameObject scoreParticle;
 
 
 //GUIText scoreText;
 AudioClip crackSound;
 
 private Color color;
 private Vector3 obj;
 
 public GameObject container;
 
 
 void  Update (){
     if (Input.GetButtonDown("Fire1")) 
     {
            //var ray= GetComponent.<Camera>().ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
         //var ray= GetComponent(Camera).ScreenPointToRay (Input.mousePosition); //ray from camera to mouse position, we use this for clicking on balls
         Ray ray = camera.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit = new RaycastHit(); 
            if ( Physics.Raycast (ray,out hit, 30.0f) ) //if we hit something
            { 
                if(hit.rigidbody)
                { //and it is rigidbody
                   obj=hit.collider.transform.position;  // hitted object's position
                   color=hit.collider.renderer.material.color; //hitted object's color
                 //hit.collider.gameObject.GetComponent(chack).Start();//enable hitted object's chack script,
                 hit.collider.gameObject.GetComponent<chack>().Start(); //enable hitted object's chack script,
                 audio.volume=0.7f;
                 audio.PlayOneShot(crackSound); //play crackSound
                 if(destroyed <= 0 && (int.Parse(container.GetComponent<instantiate>().score) >= 10))
                 { //if we clicked and don't destroyed any balls
                     //
                     var minusScore=Instantiate(scoreParticle, obj - Vector3(0,0,0.3f), Quaternion.identity) as GameObject; //instantiate scoreParticle
                     //error CS0119: Expression denotes a `type', where a `variable', `value' or `method group' was expected
                     //error CS1502: The best overloaded method match for `UnityEngine.Object.Instantiate(UnityEngine.Object, UnityEngine.Vector3, UnityEngine.Quaternion)' has some invalid arguments
                     //error CS1503: Argument `#2' cannot convert `object' expression to type `UnityEngine.Vector3'
                     //
                     minusScore.renderer.material=score10; //give material to scoreParticle
                     minusScore.renderer.material.color = color;//give ball's color to scoreParticle
                     //scoreText.text=""+(int.Parse(scoreText.text) - 10); //minus 10 to score text
                     container.GetComponent<instantiate>().score=""+(int.Parse(container.GetComponent<instantiate>().score) - 30); //minus 10 to score text
                 }
             }
         }         
     }
 }
 
 public void scoresCalculation ()
 {
     //yield WaitForSeconds (0.2f);
     //yield return new WaitForSeconds(0.2f);
 // Should i change for yield void to IEnumerator??
     if(destroyed == 3)
     {//if we destroyed 3 ball
         GameObject core1=Instantiate(scoreParticle, obj - Vector3(0,0,0.3f), Quaternion.identity); //instantiate scoreParticle
         score1.renderer.material=score30; //give material to scoreParticle
         score1.renderer.material.color = color;//give ball's color to scoreParticle
         //scoreText.text=""+(int.Parse(scoreText.text)+30); //plus 30 to score text 
         container.GetComponent<instantiate>().score=""+(int.Parse(container.GetComponent<instantiate>().score)+30); //plus 30 to score text 
     }
 }
 
 }
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Enemy AI script causing Unity to crash (Javascript to C#) 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Need help converting js to C# -- yield return WaitForSeconds 3 Answers
Can this be converted to C#? 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                