Onzzzy
1
Welcome to Unity Answers
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a user guide.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
I made the changes to get it to compile. You did a pretty good job of the translation. Your main issue was the format of GetComponent.
using UnityEngine;
using System.Collections;
using System;
public class ParticleProjectionCirle : MonoBehaviour {
public bool emit = true;
public float range = 1.0f;
public int particleCount = 16;
public float particleSize = 1.0f;
public float rotationSpeed = 0.5f;
public Color particleColor = Color.white;
public LayerMask layerMask = -1;
public 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<ParticleEmitter>();
if (!emitter) {
gameObject.AddComponent("EllipsoidParticleEmitter");
emitter = gameObject.GetComponent<ParticleEmitter>();
}
emitter.emit = false;
emitter.ClearParticles();
emitter.useWorldSpace = true;
createParticlesAry();
myTransform = transform;
}
private void createParticlesAry() {
if (particleCount < 0) {
particleCount = 0;
}
particles = new Particle[oldParticleCount];
oldParticleCount = oldParticleCount;
}
private void setParticlesCount() {
if (particles == null || (oldParticleCount != particleCount)) {
createParticlesAry();
}
}
void Update() {
setParticlesCount();
emitter.ClearParticles();
if (emit) {
float radian;
float offsetY;
center = myTransform.position;
rot += Time.deltaTime * rotationSpeed;
offsetY = particleSize / 2;
for (int cnt = 0; cnt < particleCount; cnt++) {
radian = (float)(Mathf.PI * (cnt / particleCount * 0.5) + 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;
}
particles[cnt].position = pos;
particles[cnt].color = particleColor;
particles[cnt].size = particleSize;
particles[cnt].energy = 1.0f;
particles[cnt].velocity = myTransform.up;
}
emitter.particles = particles;
}
}
}