Issue with animator not working when key is pressed - Script and Animator communication - 2D - MissingComponentException

Hello I was hoping somebody may be able to help as I have tried searching, poking and looking on forums for tuts an answers.

I am having issues with getting this to work so here goes. When the space bar is press, a blast wave will shoot out in a 2D radius - (game is 2d) The blast isnt attached to the player, it is free floating ine the scene, if you attach it to the player, the same error comes up. The code is also attached the to ‘Player’

If any one could help i would be happy.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerAtk : MonoBehaviour {

	public Animator anim;
	// Use this for initialization

	void Start (){
		anim = GetComponent.<Animator> ();
	}

	void Update()
	{
		if(Input.GetKeyDown("space"))
			
		{
			Attack();

		}
	}

	void Attack()
	{
		Debug.Log("blam!");
		// elements of what "Attack" does eg. sends rigid bodies flying, 
		// enemies flying in a radius around the player.  
		anim.Play("idle");
         //idle is a state in the mechanim
	}
}

I have also attached this.

MissingComponentException: There is no ‘Animator’ attached to the “Player” game object, but a script is trying to access it.
You probably need to add a Animator to the game object “Player”. Or your script needs to check if the component is attached before using it.

Thanks,

Could this be the problem? You have “anim = GetComponent. ();”

There is a dot in there.  It should be "anim = GetComponent<Animator> ();"

If you intend on dragging an animator into the script through the Unity Editor (as you said you did in one of your post’s comments) then you don’t need to call GetComponent in the first place. Try dragging your desired animator into the script and getting rid of the GetComponent from the code and see how it goes. Hope this ends up helping @jimm84

Thank you all, came at this from a different approach this is what I changed :-

The code, and what the code was attached to - now the child object

This appears to have fixed it, i hope this will come useful.

This script was attached to the child / blast / not the player

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BlastWave : MonoBehaviour {

	public Animator anim;
	// Use this for initialization

	void Start (){
		anim = GetComponent<Animator> ();
	}

	void Update()
	{
		if(Input.GetKeyDown("space"))

		{
			// when space is pressed play EMP animation
			anim.Play("EMP");
			Debug.Log("blam!");

		}
	}
		
}