I am a beginner at Unity I am making a 2D game and I have a character and an enemy set up. As of right now my camera follows my character but when I collide with my enemy I want my character to go flying and my camera follow script to stop following my character. How do I do this easily? Thank you in advance.
P.S. Here’s the code:
Camera Follow Script:
import System.Collections.Generic;
import UnityEngine;
public var player : GameObject;
static var offset : Vector3;
private var offsetY : Vector2;
function Start ()
{
offset = transform.position - player.transform.position;
}
function LateUpdate ()
{
transform.position = player.transform.position + offset;
}
Enemy Kill Character Script:
import System.Collections.Generic;
import UnityEngine;
public var player : GameObject;
public var script;
function Start()
{
script = GetComponent.<CameraFollow> ();
}
function OnTriggerEnter2D(other : Collider2D)
{
if(other.CompareTag("Player"))
{
player.GetComponent.<Rigidbody2D>().velocity = Vector3(-100,100);
script.enabled = false;
//Application.LoadLevel(1);
}
}
Ignore the LoadLevel part please and my camera script is called CameraFollow and my enemy script is called KillCharacter