Moving platform script not quite working

Hi all, I have been reading through the unity manual on scripting and gave myself of using what
I thought I learnt to write a moving platform script from scratch:

using UnityEngine;
using System.Collections;

public class platformMove : MonoBehaviour {
	public float speed;
	public GameObject Trig1;
	public GameObject Trig2;


	// Use this for initialization
	void Start () {

		Rigidbody rb = GetComponent<Rigidbody>();
		rigidbody2D.AddForce (new Vector2 (speed, 0f));
	
	}

	
	void OnTriggerEnter2D(Collider2D col) {

				if (col.gameObject.tag == "Trig2") {
				Debug.Log("Trigger2 found");
						rigidbody2D.AddForce (new Vector2 (-5f, 0f));
			
				}
			
			if (col.gameObject.tag == "Trig1") {
				rigidbody2D.AddForce (new Vector2 (5f, 0f));
				
			}
	
	
}
}

There are no messages in the console. The platform
starts by moving to the right but moves through the trigger (it is supposed to bounce back and forth
between the two triggers), but at least the debug is going off
when the platform hits it. I think that whatever errors are left are
probably tiny, so I was really hoping someone here could help me worm them out, before I spend the
actual entirety of the day ramming my head against it :slight_smile:

Awesome!!! I used succeeded by watching this video: How to make Doors in Unity (tutorial) - YouTube and did most of the work through the animator, a much much better method it seems. This is not only going to make production quicker but more fun.

Here is the modified code that finally has a platform smoothly moving back and forth through the animator:

using UnityEngine;
using System.Collections;

public class Pmove3 : MonoBehaviour {

    Animator animator;
    bool moveStart;

    void Start ()
    {
        moveStart = false;
        animator = GetComponent<Animator>();
    }

    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.gameObject.tag == "Player")
        {
            moveStart = true;
            Pmove3Control ("Start");
    }
}
    void OnTriggerExit2D(Collider2D col)
    {
        if(moveStart)
        {
            moveStart = false;
           Pmove3Control ("Return");
           }
 }

    void Pmove3Control(string direction)
           {
            animator.SetTrigger(direction);
        }
}

The only problem that remains is that in the demonstration he has two doors he wants to open synchronistically, so he parented the two together to an empty object and runs the animator and the trigger though there. I found that this method doesn’t work for 2d platforms, because any time one needs to tweak the platforms position, it is also moving it’s attached trigger. So I was thinking of just using one platform object, a separate non-parented trigger, and have the player be able to trigger it through calling both the player and the trigger into the platform script.

So:

public GameObject Player;
    public GameObject P3Trig;
    
    if (Player){
    void OnTriggerEnter2D(Collider2D col)
    {
        if(col.gameObject.tag == "P3Trig")
        {
            moveStart = true;
            Pmove3Control ("Start");
    }
}

But of course the syntax for that doesn’t work…but I know that the logic is close to right…Am I wrong? Thanks a ton!!!