How can I be solving these Errors in Unity 5 and adding these components?

Asked

Viewed 458 times

1

using UnityEngine;
using System.Collections;

public class RandomParticlePoint : MonoBehaviour
{
    [Range(0f, 1f)]
    public float normalizedTime;

    void OnValidate()
    { 
        particleSystem.Simulate(normalizedTime, true, true);
    }
}

Console

Problema que aparece uqnado aperto o Play

Error also appears when I start the program

1 answer

1

How to resolve the error

This error occurs because you did not convert when you had this project opened in Unity 5.

When you open a project from an old version of Unity, it will say that there are some obsolete things and ask if you want to convert to the latest one. When it does not convert it keeps the old structure, which eventually results in error in some cases.

The error you marked is about how to work with the Particle system.

In the old days you could make a direct call from him as you marked in yellow, now you need to call the Getcomponent.

http://docs.unity3d.com/Manual/class-ParticleSystem.html

Your code would look like this

using UnityEngine;
using System.Collections;

public class RandomParticlePoint : MonoBehaviour 
{
    [Range(0f, 1f)]
    public float normalizedTime;


    void OnValidate()
    {
        GetComponent<ParticleSystem>().Simulate (normalizedTime, true, true);
    }
}

How to add the component

For your code to work GetComponent the object on which you hung your script also needs to have the component you are asking for.

Here’s a video teaching how to work with the component Particle System https://www.youtube.com/watch?v=Y-Kl5jQ2A8k

Browser other questions tagged

You are not signed in. Login or sign up in order to post.