Search Unity

XAML Unity 3D error

Discussion in 'Windows' started by BlueMountain, Nov 7, 2013.

  1. BlueMountain

    BlueMountain

    Joined:
    Oct 28, 2013
    Posts:
    15
    I was overviewing the example: http://docs.unity3d.com/Documentation/Manual/wp8-unity-interaction.html .
    When I downloaded the .zip, it worked. However following it step by step keeps giving me the same error:
    Code (csharp):
    1.  
    2.  private void Unity_Loaded()
    3.         {
    4.             var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
    5.             sphereScript.SphereStateChanged += SphereStateChanged;
    6.             SphereStateChanged(sphereScript.IsSphereMoving);
    7.         }
    8.  
    9.         private void SphereStateChanged(bool currentSphereState)
    10.         {
    11.             Dispatcher.BeginInvoke(() =>
    12.             {
    13.                 SphereStateTextBlock.Text = currentSphereState ? "Sphere is moving" : "Sphere is stopped";
    14.             });
    15.         }
    Code (csharp):
    1. var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
    keeps giving me a non-generic method cant be used with type error.

    The SphereScript was copy and pasted in. I have attached the camera. I switched platform to windows phone 8 before building it. What am I doing wrong?
     
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    Where are you adding this code to? Could you paste entire error message?
     
  3. BlueMountain

    BlueMountain

    Joined:
    Oct 28, 2013
    Posts:
    15
    MainPage.xaml.cs :
    Error 1 The non-generic method 'UnityEngine.Object.FindObjectOfType(System.Type)' cannot be used with type arguments C:\*\*\Documents\Unity\Testing\Export\Testing\MainPage.xaml.cs 56 51 Testing
     
  4. BlueMountain

    BlueMountain

    Joined:
    Oct 28, 2013
    Posts:
    15
  5. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,680
    I'm afraid there might be a mistake in the tutorial. Could you try changing that line to this?

    Code (csharp):
    1. var sphereScript = UnityEngine.Object.FindObjectOfType(typeof(SphereScript)) as SphereScript;
     
  6. BlueMountain

    BlueMountain

    Joined:
    Oct 28, 2013
    Posts:
    15
    Thank You! That worked!