error CS1061
Hello,
I am quite new trying to learn Unity and I am having the following errors:
"Assets/Standard Assets/ParticleSystems/Scripts/WaterHoseParticles.cs(43,13): error CS1061: Type UnityEngine.Component' does not contain a definition for attachedRigidbody' and no extension method attachedRigidbody' of type UnityEngine.Component' could be found. Are you missing an assembly reference?"
"Assets/Standard Assets/ParticleSystems/Scripts/WaterHoseParticles.cs(46,10): error CS1061: Type UnityEngine.Component' does not contain a definition for attachedRigidbody' and no extension method attachedRigidbody' of type UnityEngine.Component' could be found. Are you missing an assembly reference?"
I tried to look up the solution over here but I have been unsuccessful. I copy paste the code:
using System;
using UnityEngine;
namespace UnityStandardAssets.Effects
{
public class WaterHoseParticles : MonoBehaviour
{
public static float lastSoundTime;
public float force = 1;
private ParticleCollisionEvent[] m_CollisionEvents = new ParticleCollisionEvent[16];
private ParticleSystem m_ParticleSystem;
private void Start()
{
m_ParticleSystem = GetComponent<ParticleSystem>();
}
private void OnParticleCollision(GameObject other)
{
int safeLength = m_ParticleSystem.GetSafeCollisionEventSize();
if (m_CollisionEvents.Length < safeLength)
{
m_CollisionEvents = new ParticleCollisionEvent[safeLength];
}
int numCollisionEvents = m_ParticleSystem.GetCollisionEvents(other, m_CollisionEvents);
int i = 0;
while (i < numCollisionEvents)
{
if (Time.time > lastSoundTime + 0.2f)
{
lastSoundTime = Time.time;
}
var col = m_CollisionEvents[i].colliderComponent;
if (col.attachedRigidbody != null)
{
Vector3 vel = m_CollisionEvents[i].velocity;
col.attachedRigidbody.AddForce(vel*force, ForceMode.Impulse);
}
other.BroadcastMessage("Extinguish", SendMessageOptions.DontRequireReceiver);
i++;
}
}
}
}
Answer by The_Icaruz · May 18, 2018 at 06:12 AM
You never declared the term "attachedRigidboy".
Under your public float force = 1; line you could declare the Rigidbody component.
// If you're using a Rigidbody3D
private Rigidbody attachedRigidbody;
// If you're using a Rigidbody2D
priavte Rigidbody2D attachedRigidbody;
Wether it should be "priavte" or "public" just change it like you need it.
In your start method you could write this line of code :
// If you're using a Rigidbody3D
attachedRigidbody = GetComponent<Rigidbody> ();
//If you're using a Rigidbody2D
attachedRigidbody = GetComponent<Rigidbody2D> ();
Your answer