- Home /
How can I make this script work ?
I wanted to create a script to make the camera move after we entered in a box collider. However I'm not very good in programming and I tried to follow another script but it doesn't work, Can somebody help me ? Here is the script. For information, the debug.log doesn't work. Thanks for answering !
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class CameraShake : MonoBehaviour { private bool isShaking = false;
private float baseX, baseY;
private float intensity =0.1f;
private int shakes = 0;
void OnTriggerEnter2D (Collider2D other) {
if (other.gameObject.tag == "Player") {
isShaking = true;
Debug.Log ("hello");
}
}
void Start ()
{
baseX = transform.position.x;
baseY = transform.position.y;
}
void UpDate () {
if (isShaking = true) {
float randomShakeX = Random.Range (-intensity, intensity);
float randomShakeY = Random.Range (-intensity, intensity);
transform.position = new Vector2 (baseX + randomShakeX, baseY + randomShakeY);
shakes--;
}
if(shakes<=0)
{
isShaking = false;
transform.position = new Vector2(baseX, baseY);
}
}
public void MinorShake(float in_intensity)
{
isShaking = true;
shakes = 10;
intensity = in_intensity;
}
public void LongShake(float in_intensity)
{
isShaking = true;
shakes = 100;
intensity = in_intensity;
}
}
$$anonymous$$ight want to change void UpDate to void Update first and see if that was the problem since it's case sensitive
Thanks for your answer ! I'm french and I'm not very good in english so I'm not sure to understood well your advice, but If i understood well i remove the void Update at the first top of the script but it still doesn't work :/
yaezah indique que le nom de la fonction est Update
et non UpDate
. C# est sensible à la casse des caractères.
Oh yes you were right it was the problem ! Thank you very much for your help !