- Home /
Particle circle HELP
I use c sharp but I wanted to use the code from http://www.smokymonkeys.com/kyrill/ I converted java to c# and I don't understand how get rid of these few errors, can you guy take a look and see what might be causing them?
using UnityEngine; using System.Collections;
[ExecuteInEditMode]
public class rings : MonoBehaviour {
bool emit = true;
float range = 1.0f;
int particleCount = 16;
float particleSize = 1.0f;
float rotationSpeed = 0.5f;
Color particleColor = Color.white;
LayerMask layerMask = -1;
float castMaxDistance = Mathf.Infinity;
private int oldParticleCount; private ParticleEmitter emitter; private Particle[] particles;
private float rot;
private Vector3 center; private Vector3 pos; private RaycastHit hit;
private Transform myTransform;
void Awake (){
emitter = gameObject.GetComponent();
if (!emitter) {
gameObject.AddComponent<EllipsoidParticleEmitter>();
emitter = gameObject.GetComponent();
}
emitter.emit = false;
emitter.ClearParticles();
emitter.useWorldSpace = true;
createParticlesAry();
myTransform = transform;
}
private void createParticlesAry (){
if (particleCount < 0) {particleCount = 0;
}
particles = new Particle[particleCount];
oldParticleCount = particleCount;
}
private void setParticlesCount (){
if (!particles || (oldParticleCount != particleCount)){
createParticlesAry(); } }
void Update (){
setParticlesCount();
emitter.ClearParticles();
if (emit) {
int i;
float radian;
float offsetY;
Vector3 center;
Vector3 pos;
RaycastHit hit;
center = myTransform.position;
rot += Time.deltaTime *rotationSpeed;
offsetY = particleSize /2;
for (i = 0; i < particleCount; i++) {
radian = Mathf.PI *(i /(particleCount *0.5f)) +rot;
pos.x = range *Mathf.Cos(radian) +center.x;
pos.y = center.y;
pos.z = range *Mathf.Sin(radian) +center.z;
if (Physics.Raycast(pos, -myTransform.up, out hit, castMaxDistance, layerMask)) {
pos.y = hit.point.y +offsetY;
}
Debug.DrawRay(pos, myTransform.up *hit.distance, Color.red);
particles[i].position = pos;
particles[i].color = particleColor;
particles[i].size = particleSize;
particles[i].energy = 1.0f;
particles[i].velocity = myTransform.up;
}
emitter.particles = particles;
}
}
}
The errors that im getting are:
Assets/rings.cs(25,22): error CS0411: The type arguments for method
UnityEngine.GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly > Assets/rings.cs(28,25): error CS0246: The type or namespace name
EllipsoidParticleEmitter' could not be found. Are you missing a using directive or an assembly reference?Assets/rings.cs(29,22): error CS0411: The type arguments for method
UnityEngine.GameObject.GetComponent<T>()' cannot be inferred from the usage. Try specifying the type arguments explicitly > Assets/rings.cs(47,5): error CS1955: The member
rings.particles' cannot be used as method or delegate
Please help
Answer by dannyskim · Nov 07, 2011 at 06:27 PM
The errors seem pretty self explanatory to me. For GetComponent, you're not passing in any kind of argument when you set the value in the Awake(). It's basically asking you, what are you looking for? It may work in Javascript, but it doesn't work in C# because C# requires much more strict typecasting. In Javascript, you typically are able to dynamically typecast because the compiler will sort it out for you, but that's not the case in C#. Find exactly what you are looking for and declare the type when you're utilizing GetComponent in C#.
I could be wrong, but I am not personally aware of an EllipsoidParticleEmitter component anywhere in the UnityEngine. There's a ParticleEmitter component though, so I'm not quite sure what they were trying to do there.
Your answer
Follow this Question
Related Questions
Getting index of the smallest number in a list 1 Answer
NullReferenceException problem 2 Answers
Missing Reference FPS help 1 Answer
Convert to C#,I don't know how to convert this 1 Answer
Null in GetValidMethodInfo 0 Answers