RuanMV
RuanMV

Reputation: 21

Unity The type 'TitleAnimScript' conflicts with the type 'TitleAnimScript'

I am trying call a function from a script on another game object to play an animation clip, but it gives me the following error:

The type 'TitleAnimScript' in 'c:\Users\ruanv\Documents\Unity Projects\Project_MathNinja\Assets\Scripts\TitleAnimScript.cs' conflicts with the imported type 'TitleAnimScript' in 'Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'. Using the type defined in 'c:\Users\ruanv\Documents\Unity Projects\Project_MathNinja\Assets\Scripts\TitleAnimScript.cs'. [Assembly-CSharp]

The error is in this 'SceneManagerScript.cs' script:

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

public class SceneManagerScript : MonoBehaviour
{
    [SerializeField]
    private GameObject mainMenuButtons;
    [SerializeField]
    private GameObject levelSelectButtons;

    private TitleAnimScript titleAnimScript;

    void Start()
    {
        // adsf
    }

    public void QuitApp()
    {
        Application.Quit();
    }

    public void LevelSelect()
    {
        mainMenuButtons.SetActive(false);
        titleAnimScript.playAnimClip();
        levelSelectButtons.SetActive(true);
    }
}

And this is the 'TitleAnimScript.cs' script:

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

public class TitleAnimScript : MonoBehaviour
{
    private Animator titleTextAnim;

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

    public void playAnimClip()
    {
        titleTextAnim.SetTrigger("playClip");
    }
}

Upvotes: 2

Views: 300

Answers (1)

Milan Egon Votrubec
Milan Egon Votrubec

Reputation: 4049

It sounds like you've made a copy of your TitleAnimScript in a reserved folder. These reserved folder will compile to a sperate DLL called, as you could guess, Assembly-CSharp-firstpass. They're created as two separate projects, which is why the IDE won't pick it up as an error, but because you're referencing Assembly-CSharp AND Assembly-CSharp-firstpass, the solution is seeing two versions of TitleAnimScript.

Check your reserved folders, as described on this page, for any second occurrences of your TitleAnimScript. It could be that you just accidently copied it across at some stage.

For a quick refernce, the folders are:

  • Editor
  • Editor Default Resources
  • Gizmos
  • Plugins
  • Resources
  • Standard Assets
  • StreamingAssets

Upvotes: 0

Related Questions