I'm following a tutorial to create some jelly effects to a slime platformer character, the script is divided in two parts that I called "JellyBro" that makes the vertex jiggle and "jellyfier" that makes my Player bounce. The script doesn't have any typos and it should be working except for the Null Reference Exception that when I click brings me to a random part of my script...
I'm really new to scripts and stuff so I have no idea what it could be and other similar questions in the forums didn't really help
using System.Collections.Generic;
using UnityEngine;
public class jellyfier : MonoBehaviour
{
public float bounceSpeed;
public float fallForce;
public float stiffness;
private MeshFilter meshFilter;
private Mesh mesh;
Jelly[] jellyVertices;
Vector3[] currentMeshVertices;
private void Start()
{
meshFilter = GetComponent<MeshFilter>();
mesh = meshFilter.mesh;
GetVertices();
}
private void GetVertices()
{
jellyVertices = new JellyBro[mesh.vertices.Length];
currentMeshVertices = new Vector3[mesh.vertices.Length];
for (int i = 0; i < mesh.vertices.Length ; i++)
{
jellyVertices[i] = new JellyBro(i,mesh.vertices[i], mesh.vertices[i], Vector3.zero);
currentMeshVertices[i] = mesh.vertices[i];
}
}
private void Update()
{
UpdateVertices();
}
private void UpdateVertices()
{
for (int i = 0; i < jellyVertices.Length; i++)
{
jellyVertices[i].UpdateVelocity(bounceSpeed);
jellyVertices[i].Settle(stiffness);
jellyVertices[i].currentVertexPosition += jellyVertices[i].currentVelocity * Time.deltaTime;
currentMeshVertices[i] = jellyVertices[i].currentVertexPosition;
}
mesh.vertices = currentMeshVertices;
mesh.RecalculateBounds();
mesh.RecalculateNormals();
mesh.RecalculateTangents();
}
public void OnCollisionEnter(Collision other)
{
ContactPoint[] CollisionPoints = other.contacts;
for (int i = 0; i < CollisionPoints.Length; i++)
{
Vector3 inputPoint = CollisionPoints[i].point + (CollisionPoints[i].point * .1f);
ApplyPressureToPoint(inputPoint, fallForce);
}
}
public void ApplyPressureToPoint(Vector3 _point, float _pressure)
{
for (int i = 0; i < jellyVertices.Length; i++)
{
jellyVertices[i].ApplyPressureToVertex(transform, _point, _pressure);
}
}
}
So yeah I'm making this game for my portfolio so I really want it to be simple but well done and this shoot is stressing me out ha ha
Thanks a lot in advance