- Home /
js to C# - Instantiate(scoreParticle, object - Vector3(0,0,0.3), Quaternion.identity)
Hi! need help to js to C# convertion
Jscript code:
#pragma strict
#pragma implicit
#pragma downcast
private var object:Vector3;
var scoreParticle:GameObject;
function Update()
{
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
}
Answer by Ashkan_gc · Oct 13, 2012 at 01:42 PM
You should rename object and keep in mind that the result of instantiate (like what you did) can only be casted to the type that you declared for your prefab on top.
public class YourScriptFileName : MonoBehaviour
{
private Vector3 objPosition;
public GameObject scoreParticle=null; //null is required to eliminate warning 649
void Update()
{
var minusScore = Instantiate(scoreParticle,objPosition - new Vector3(0,0,0.3f),Quaternion.identity) as GameObject;
minusScore.renderer.material = score10;
minusScore.renderer.material.color = color;
}
}
var keyword in C# is different, it will not declare a dynamic variable and like your #pragma strict js codes, it always disallow converting a variable to another type, it just tells the C# compiler to see the type of the variable in the return type of the expression in front of it. Oh did i sounded to technical? The variable will have the type of the result of the Instantiate and the cast.
Your answer
![](https://koobas.hobune.stream/wayback/20220613082255im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
JS to C#, anyone? 1 Answer
Can this be converted to C#? 1 Answer
Need help converting js to C# -- GUIStyle 2 Answers
Need help converting js to C# 1 Answer
js to C# - 0 Answers