Problem with 2 scripts "working together"

First script attached on GameObject named “Chkp1” with 2D collider set as trigger.
using UnityEngine;
using System.Collections;

public class Checkpoint : MonoBehaviour {
			public bool Chkp = false;
		 	GameObject hero;
		 	GameObject ChkpLoc;
			
	void OnTriggerEnter2D(Collider2D col)
	{
			if(col.gameObject.tag == "Player")
			{
				Chkp = true;
			}
	}
	public void Respawn()
	{
		hero = GameObject.Find("MainChar");
		ChkpLoc = GameObject.Find("Chkp1");
		hero.transform.position = ChkpLoc.transform.position;
		hero.rigidbody2D.velocity = new Vector2 (0, 0);
	}
}

Second script attached to MainCamera with 2d box collider set as trigger.
using UnityEngine;
using System.Collections;

public class CameraChkp : Checkpoint {
	void OnTriggerExit2D(Collider2D col)
	{
		if (Chkp == true) 
		{
			Respawn ();
		} 
		else 
		{
			Application.LoadLevel(Application.loadedLevel);	
		}
	}
}

So the game is setup when if you leave MainCamera, eather you get spawned in checkpoint or retart the level. The problem is, when I start the game, something starts the trigger and Chkp is from start of the game becomes true instantly. So when I try to leave the screen, it gets teleported to checkpoint even my MainChar has newer touched the checkpoints trigger. Does any one know whats wrong with the script or way how unity works of why it automaticly sets Chkp as true even if its trigger is way off (even out of borders from MainCamera trigger).

Its been alluded to in other answers, but you have some big problems in your structure. Here is what’s happening

CameraChkp inherits from Checkpoint. This means that it runs all of the code that Checkpoint does. So as long as the player starts the game in the trigger of CameraChkp then CameraChkp.Chpk will be true. This is the value you are checking.

Meanwhile your Checkpoint.Chpk on your checkpoint is sitting there returning false until the player touches it, as designed.

Here is some quick code to fix.

public class Checkpoint : MonoBehaviour {
    public bool touched {get; private set;}
 
    void OnTriggerEnter2D(Collider2D col) {
        if(col.gameObject.tag == "Player") {
           touched = true;
        }
    }
}

Note the Checkpoint class is only responsible for one thing, setting touched to true. The touched variable is renamed, because Chpk will make no sense in six months when you decided to change the checkpoint behaviour. I’ve also made its setter private. No other class has any business setting the checkpoint to true.

public class ResawnIfOffScreen : MonoBehaviour {
   private Checkpoint checkpoint;
   private GameObject hero;
   private Vector3 startPosition;
 
   void Start(){
      startPosition = transform.position;
      checkpoint = GameObject.Find("Checkpoint").GetComponent<Checkpoint>(); 
      hero = GameObject.Find("MainChar");
   }
 
    void OnTriggerExit2D(Collider2D col){
        if (checkpoint.touched == true){
            Respawn (checkpoint.transform.position);
        } 
        else {
            Respawn (startPosition);    
        }
    }

    public void Respawn(Vector3 spawnPosition) {
        hero.transform.position = spawnPosition;
        hero.rigidbody2D.velocity = new Vector2 (0, 0);
    }
}

Again some significant changes. First up this inherits from MonoBehaviour. Second it gets the respawn method, it makes more sense to have it here. Respawn method gets passed a Vector3, making it far more versatile. Also allows you to eliminate the level load, as these tend to kill performance (you can add it back in if needed). It also has the code to get the various references it needs in start. I also renamed it, because CameraChkp makes no sense whatsoever. There are also some other general clean-ups, because I can’t have bad code with my name at the bottom.

Variables and properties of one script cannot be accessed by another script by default. You need to either make the property static with something like:

public static bool Chkp = false;

and then access it in your other script as:

if (Checkpoint.Chkp)
{
  // Do Something
}

Or you need to create some method for accessing the property. This can be done by creating a reference to the Checkpoint class by adding it as a property in your CameraChkp class and then dragging the GameObject onto the reference in the Unity Editor:

public class CameraChkp : Checkpoint {
    public Checkpoint checkpoint;

    void OnTriggerExit2D(Collider2D col)
    {
        if (checkpoint.Chkp == true) 
        {
            Respawn ();
        } 
        else 
        {
            Application.LoadLevel(Application.loadedLevel);    
        }
    }
}

or you can load the reference on Start

public class CameraChkp : Checkpoint {
    private Checkpoint checkpoint;

   void Start()
   {
      checkpoint = GameObject.Find("Checkpoint").GetComponent<Checkpoint>(); 
      // Find("Checkpoint") - Checkpoint refers to the name of the gameobject
   }

    void OnTriggerExit2D(Collider2D col)
    {
        if (checkpoint.Chkp == true) 
        {
            Respawn ();
        } 
        else 
        {
            Application.LoadLevel(Application.loadedLevel);    
        }
    }
}

Lastly, if you are accessing another Class’s properties from another script you should always consider using a getter/setter instead of exposing the property itself.

You really don’t want to have the second script inherit from the first script. By doing so, you’ve made it so the Player being in-bounds of the camera will trigger Chkp = true;
This is happening because by inheriting, you’re giving the camera script both the OnTriggerExit2D AND the OnTriggerEnter2D methods.

Here is my proposed alternative (please keep in mind that this is only one way to do it):
Attach a script to you player which has a public GameObject LastCheckpoint field. (or add it to the existing player script if you have one).

Modify the camera script so that the OnTriggerExit2D method checks the LastCheckpoint field on the player. If it is null, send the player to the start. If it is not null, send the player there.

Modify the Checkpoint script so that the OnTriggerEnter2D method is triggered by the player, the player’s LastCheckpoint object is set the the game object to which the script is attached. – Alternatively you could probably just store the Transform instead of the whole GameObject.

As a bonus for doing it this way, if you have more than one checkpoint, the player will always go to the most recently triggered one.