- Home /
Possible Particle function?
I am playing around with different particle system methods and I was wondering if someone could help me out. I do not know how to turn of the sphere collider in script, as well as this error which appears: (25,1): BCE0077: It is not possible to invoke an expression of type 'UnityEngine.Transform'. In general I'm just curious if anyone could tell me if this type of system would work :)
Thanks!
//Variables (START)_________
//The particles that will Instantiate on hit
var Particle1 : Transform;
//Speed of the Bullet
var bulletSpeed = 10;
var expireTime = 10;
//Variables (END)___________
function Start ()
{
//A soon as the projectile is created, make sure
//destroys itself
Destroy (gameObject, expireTime);
}
function Update ()
{
//Sends the projectile forward
transform(Vector3.forward * bulletSpeed * Time.deltaTime);
}
function OnCollisionEnter (hit : Collision)
{
if(hit.transform.tag == "floorMud")
{
Instantiate(Particle1, transform.position, transform.rotation);
transform.renderer.enabled = false;
transform.spherecollider.enabled = false;
}
}
Answer by Benproductions1 · May 23, 2013 at 11:21 PM
Hello,
Your error is due to you trying to call a variable as a function.
In your Update function you call transform()
, but transform
references the Transform
component of the GameObject
your script is attached to. You can't call a Transform
as a function, it just doesn't work that way. What you can do is access it's position and so something like this:
transform.position += Vector3.forward * bulletSpeed * Time.deltaTime;
This will then change the position
of the Transform
component of the GameObject
to whatever :)
Hope this helps,
Benproductions1
Thanks for the help! The problem with this method is that I get a really weird instantiation angle. I got the good o'l C# and wrote this script:
//Variables Start
//Quick Reference
private Transform myTransform;
//Speed of the Projectile
private float projectileSpeed = 100;
//Time till Projectile Destroys itself
private float expireTime = 10;
//Variables End
// Use this for initialization
void Start ()
{
myTransform = transform;
//As soon as the projectile is created start a countdown
//to destroy it.
StartCoroutine(Destroy$$anonymous$$yselfAfterSomeTime());
}
// Update is called once per frame
void Update () {
myTransform.Translate(Vector3.forward * projectileSpeed * Time.deltaTime);
}
IEnumerator Destroy$$anonymous$$yselfAfterSomeTime()
{
//Wait for the timer to count up to the expireTime
//and then destroy the projectile.
yield return new WaitForSeconds(expireTime);
Destroy(myTransform.gameObject);
}
}
And in another Java I still have the rest of the script. But the particle doesnt indicate a hit as it doesn't instantiate! Could you help me with this?
@Borzi, if you have another question, ask another question. Don't post a comment :)
Oh okay I thought that was kinda "included" in my question xD Well thanks I guess.
Answer by Synergetik · May 24, 2013 at 06:16 PM
For the sphere collider you can add : gameObject.GetComponent(SphereCollider).enabled = false;
or if you want to destroy the object just use destroy(gameObject);
Thanks for you answer :) destroy(gameObject) would only destroy the Projectile immediately, whereas I wanted it to destroy itself after some time. Thanks for the gameObject.GetComponent(SphereCollider).enabled = false; though, i think its working (im kinda stuck because the whole system doesn't seem to recognize a hit).
You can just add destroy(gameObject, 1.0f)which will destroy the game object after 1 second or any other value you enter. Sorry for the delayed answer.
Your answer
Follow this Question
Related Questions
special advance gun attack 2 Answers
Android: FPS halt when doing things for the first time 2 Answers
How to speed up a trigger enter function? 1 Answer
How to create shoots 2 Answers
Particles , Altas or Separate ? 0 Answers