locked
I need some unity help RRS feed

  • Question

  • so this is my code for the enemy movement:

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Security.Cryptography.X509Certificates;
    using UnityEngine;

    public class Enemy_Movement : MonoBehaviour
    {

        public float moveSpeed = 5f;
        public int randomNumber;
        Vector2 movement;
        public GameObject prefab;


        private void PickNumber(int maxInt)
        {
            int randomNumber = Random.Range(0, maxInt + 1);
        }
        // Update is called once per frame
        void Update()
        {
            if (randomNumber.x == 0) ;
            {
                movement.x = 1;
                System.Threading.Thread.Sleep(2000);
                movement.x = -1;
                System.Threading.Thread.Sleep(4000);
                movement.x = 1;
                System.Threading.Thread.Sleep(2000);
                movement.x = 0;
                PickNumber(2);

            }
            if (randomNumber == 1) ;
            {
                movement.x = 1;
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.x = 1;
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.x = -1;
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.x = -1;
                movement.y = -1;
                System.Threading.Thread.Sleep(2000);
                movement.x = -1;
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.x = 1;
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.x = 1;
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.x = 0;
                movement.y = 0;
                PickNumber(2);

            }
            if (randomNumber == 2) ;
            {
                movement.x = 1;
                System.Threading.Thread.Sleep(2000);
                movement.x = -1;
                System.Threading.Thread.Sleep(4000);
                movement.x = 1;
                System.Threading.Thread.Sleep(2000);
                movement.x = 0;

            }
            if (randomNumber == 2) ;
            {
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.y = 1;
                System.Threading.Thread.Sleep(1000);
                movement.y = -1;
                System.Threading.Thread.Sleep(1000);
                movement.y = 0;
                PickNumber(2);
            }

            void FixedUpdate()
            {
                rb.MovePosition(rb.position + movement * moveSpeed * Time.fixedDeltaTime);
            }
        }
    }

    however the unity console returns

    Assets\Enemy_Movement.cs(18,28): error CS0104: 'Random' is an ambiguous reference between 'UnityEngine.Random' and 'System.Random'

    I have absolutely no idea how to fix this. Please help. 

    Monday, July 20, 2020 6:51 PM

All replies

  • Try this fix:

       int randomNumber = UnityEngine.Random.Range(0, maxInt + 1);

    and show the next errors, if any.


    • Edited by Viorel_MVP Monday, July 20, 2020 7:42 PM
    Monday, July 20, 2020 7:39 PM
  • Hi BiggieMiller,

    How is the question going? If your question has been answered then please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue.

    Besides, if you have more questions about Unity, I suggest you post them on the Unity forum for more help.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Wednesday, July 22, 2020 5:42 AM