Make object go to another object

I want my object C(self) to go to object B.

this is my way of doing it:

        public int speed = 5;

    	public Transform target;
    	public int strength = 1;
    
    	// Update is called once per frame
    	void Update () 
    	{
    	transform.Rotate(target.rotation.x,0,0);
    		
    	
    	transform.position+=new Vector3(0,0,1);
    	}

I am new to unity but according to my theory i will let ObjectC(self) rotate towards ObjectD and then go towards that direction.
but it is not working, if there is another easier way for it to be done pleas let me know.
Thank you in advanced.

Matching the following object’s rotation to the target rotation does not point them at each other. See Transform.LookAt() instead. Also you your Vector3(0,0,1) is in world coordinates, so it is going to go towards positive z, not move towards where the front of the object is facing. See Transform.forward. A common way folks accomplish what you are trying to do here is:

float speed = 5.0f;
public Transform target;

void Update () 
{
	    transform.LookAt(target);
	
	    transform.position += transform.forward * speed * Time.deltaTime;
}

Thank you very much, i am glad that i was a little close :smiley: