Exemplo n.º 1
0
    void Collect()
    {
        if (pickup == null)
        {
            return;
        }

        //Cria uma referência para a classe SphereScript e tenta acessá-la através do GameObject "pickup"
        SphereScript sphereScript = pickup.GetComponent <SphereScript>();

        //Se a referência não tem valor nulo...
        if (sphereScript != null)
        {
            //Se a esfera ainda não foi plataformed
            if (sphereScript.IsPlataformed)  //sphereScript.IsPlataformed == true
            {
                Debug.Log("Essa esfera já foi plataformed");
                return;
            }
            //Transformar o objeto armazenado na referência em filho deste Transform(Jogador)
            pickup.parent = transform;
            //Cria um vetor para definir a nova posição da esfera
            Vector3 novaPosicao = new Vector3(0, .5f, 0);
            //Mudar a posição do objeto em relação ao pai
            pickup.localPosition = novaPosicao;
            //Altera o valor de "isCarrying" para true, variável que controla a ação de input
            isCarrying = true;
            //Altera o valor da propriedade "IsDropped" para falso
            sphereScript.IsDropped = false;
            //Definir a variável "Player" do "sphereScript" como este objeto
            sphereScript.Player = this;
        }
    }
Exemplo n.º 2
0
    void Drop()
    {
        if (pickup == null)
        {
            return;
        }

        //Deixar o objeto coletado sem pai
        pickup.parent = null;
        //Cria um Vector3 e armazena as coordenadas x e z do jogador
        Vector3 dropPosition = new Vector3(transform.position.x, 0, transform.position.z);

        //Definir a posicao do objeto para o valor do Vector3
        pickup.position = dropPosition;
        //Altera o valor de "isCarrying" para false
        isCarrying = false;
        //Cria uma referência para a classe SphereScript e tenta acessá-la através do GameObject "pickup"
        SphereScript sphereScript = pickup.GetComponent <SphereScript>();

        //Se a referência não tem valor nulo...
        if (sphereScript != null)
        {
            //Altera o valor da propriedade "IsDropped" para true
            sphereScript.IsDropped = true;
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        plane = ObserverScript.CheckPlaneToSphereCollision(this);

        ResolvePlaneCollision();

        SphereScript sphere2 = ObserverScript.CheckSphereOnSphereCollisions(this);
    }
Exemplo n.º 4
0
    // Start is called before the first frame update
    void Start()
    {
        GameObject   sphere       = GameObject.Find("Sphere");
        SphereScript sphereScript = sphere.GetComponent <SphereScript>();

        rb            = GetComponent <Rigidbody>();
        moveDirection = sphereScript.moveDirection;
        speed         = sphereScript.speed;
    }
 private void DoTriggerPressed(object sender, ControllerInteractionEventArgs e)
 {
     if (_sphereTargeted)
     {
         SphereScript _sphere = _targetSphere.GetComponent <SphereScript>();
         _sphere.DestroySphere();
         _sphere = null;
     }
 }
Exemplo n.º 6
0
    // Update is called once per frame
    void Update()
    {
        Mesh m1 = SphereScript.BuildMesh(Vector3.zero, 0.2f, 32, Color.white);
        Mesh m2 = SphereScript.BuildMesh(TestVector, 0.2f, 32, Color.white);
        Mesh m3 = SphereScript.BuildMesh(Quaternion.Euler(RotationVector) * TestVector, 0.2f, 32, Color.white);

        filter.mesh  = m1;
        filter2.mesh = m2;
        filter3.mesh = m3;
    }
Exemplo n.º 7
0
 // Use this for initialization
 void Start()
 {
     RG = GetComponent <Rigidbody>();
     T  = RG.transform;
     SS = GameObject.FindGameObjectWithTag("Sphere").GetComponent <SphereScript>();
     if (Node != null)
     {
         NS = Node.GetComponent <NodeScript>();
     }
 }
Exemplo n.º 8
0
    /// <summary>
    /// Событие касание платформы сферой
    /// </summary>
    /// <param name="sender">Sender.</param>
    void SpereOnPlatformAction(SphereScript sender)
    {
        PointsCount++;
        sender.PhysicsLocked(true);
        var particle = (GameObject)Instantiate(collision_particle, sender.transform.position, Quaternion.identity);

        NetworkServer.Spawn(particle);
        Destroy(particle, 1f);
        sender.DestroySphere();
    }
Exemplo n.º 9
0
 void Start()
 {
     if (isLocalPlayer)
     {
         ownerObj = this;
         GetComponent <MeshRenderer>().material.color = Color.red;
     }
     spawnPoints = FindObjectsOfType <NetworkStartPosition>();
     HP          = 100;
 }
Exemplo n.º 10
0
    public override void OnInspectorGUI()
    {
        //base.OnInspectorGUI();

        SphereScript sphere = (SphereScript)target;

        GUILayout.Label("Oscillates around a base size.");
        sphere.baseSize = EditorGUILayout.Slider("Size", sphere.baseSize, .1f, 2f);

        sphere.transform.localScale = Vector3.one * sphere.baseSize;
    }
Exemplo n.º 11
0
    void Start()
    {
        padScript    = GameObject.Find("Pad").GetComponent <PadScript>();
        sphereScript = GameObject.Find("Sphere").GetComponent <SphereScript>();
        cannon.SetActive(false);


        GameObject brickArea = GameObject.Find("BrickArea");

        float brickWidth = (brickArea.renderer.bounds.size.x - brickWidthGap * (brickColumns - 1)) / brickColumns;

        print(brickWidth);

        float brickHeight = (brickArea.renderer.bounds.size.z - brickHeightGap * (brickRows - 1)) / brickRows;

        print(brickHeight);

        Vector3 bricksStart = new Vector3();

        bricksStart   = brickArea.transform.position - brickArea.renderer.bounds.size / 2;
        bricksStart.z = brickArea.transform.position.z + brickArea.renderer.bounds.size.z / 2;

        bricksStart.x += brickWidth / 2;
        bricksStart.z -= brickHeight / 2;

        print(bricksStart);


        int   index = 0;
        float x = bricksStart.x, z = bricksStart.z;

        for (int i = 0; i < brickRows; i++)
        {
            for (int j = 0; j < brickColumns; j++)
            {
                float yPos = 0;

                bricks[index]            = (Transform)Instantiate(prefabBrick, new Vector3(x, yPos, z), new Quaternion(0, 180, 0, 0));
                bricks[index].localScale = new Vector3(brickWidth, bricks[index].localScale.y, brickHeight);
                index++;

                x += brickWidth + brickWidthGap;
            }
            x = bricksStart.x;            // reset x bricks start to initial one

            z -= brickHeight + brickHeightGap;
        }


        _brickCounter = bricks.Length;
        _count        = 0;
    }
Exemplo n.º 12
0
 void DoWork()
 {
     if (sphereBundle != null)
     {
         TextureUtils.FillTextures();
         GameObject   gameObj      = UnityEngine.Object.Instantiate(sphereBundle.mainAsset) as GameObject;
         SphereScript sphereScript = gameObj.GetComponent <SphereScript>();
         if (sphereScript != null)
         {
             sphereScript.InitializeSphere();
         }
     }
 }
Exemplo n.º 13
0
 void OnMouseDown()
 {
     if (gameObject != null)
     {
         SphereScript sphere = gameObject.GetComponent <SphereScript>();
         //взяли сферу, на которую нажали, если она есть (объект является сферой и он существует), то увеличичваем счет в игре и уничтожаем объект сферы
         if (sphere != null)
         {
             sphere.PlayShoot();
             MainScene.AllPoints += sphere.PointsCount;
             Destroy(gameObject);
             _divValue = MainScene.AllPoints / 1000;
         }
     }
 }
Exemplo n.º 14
0
    private Vector3 FindPointOfImpact(SphereScript sphere2)
    {
        Vector3 pointOfImpact = new Vector3(0, 0, 0);

        float d = 0;

        d = (float)Math.Sqrt(Math.Pow(point1.x - point2.x, 2) + Math.Pow(point1.y - point2.y, 2) + Math.Pow(point1.z - point2.z, 2));

        if (d <= radius + sphere2.radius)
        {
            pointOfImpact = point1 - (radius * FindNormal(sphere2));
        }

        return(pointOfImpact);
    }
Exemplo n.º 15
0
    private void OnCollisionEnter(Collision collision)
    {
        if (collision.collider.tag == "Sphere")
        {
            SphereScript sphereScript = collision.collider.GetComponent <SphereScript>();
            if (sphereScript.ColorType == ColorType && gameObject.activeInHierarchy && sphereScript.CurrentSize == CurrentSize)
            {
                CurrentSize += (int)collision.gameObject.GetComponent <SphereScript>().CurrentSize;
                collision.gameObject.SetActive(false);
                Destroy(collision.gameObject);

                GameManagerScript.Instance.UpdateState(ColorType, CurrentSize);
                transform.localScale = Vector3.one;

                transform.localScale *= (int)CurrentSize;
            }
        }
    }
Exemplo n.º 16
0
    //Returns the plane that the passed in sphere is colliding with
    public static PlaneScript CheckPlaneToSphereCollision(SphereScript sphere)
    {
        float       distanceFromCenterToPlane, d2;
        PlaneScript collidingPlane = new PlaneScript();

        foreach (PlaneScript plane in planes)
        {
            distanceFromCenterToPlane = plane.DistanceTo(sphere.transform.position);
            d2 = distanceFromCenterToPlane - sphere.radius;

            if (d2 <= 0)
            {
                collidingPlane = plane;
            }
        }

        return(collidingPlane);
    }
Exemplo n.º 17
0
    //Checks to see what spheres are colliding
    public static SphereScript CheckSphereOnSphereCollisions(SphereScript sphere1)
    {
        SphereScript sphere2;

        for (int i = 0; i < spheres.Count - 1; i++)
        {
            sphere2 = spheres[i];

            if (sphere1.transform.position != sphere2.transform.position)
            {
                if (Vector3.Distance(sphere1.transform.position, sphere2.transform.position) < (sphere2.radius + sphere1.radius))
                {
                    sphere2.ResolveSphereCollision(sphere1);
                    return(sphere2);
                }
            }
        }
        return(null);
    }
Exemplo n.º 18
0
    public static void BuildMesh(Transform parent, LinePoints[] curves, Material material, float lineRadius, int sphereIterations, int cylinderCapSegments, Color vertexColor)
    {
        DeleteChildObjects(parent, "Curve");
        for (int z = 0; z < curves.Length; z++)
        {
            for (int v = 0; v < curves[z].Points.Length; v++)
            {
                Mesh m = SphereScript.BuildMesh(curves[z].Points[v], lineRadius, sphereIterations, vertexColor);
                m = NormalSolver.RecalculateNormals(m, 75f);
                CreateChildObject(parent, "Curve_" + z + "_Sphere_" + v, m, material);

                if (v < curves[z].Points.Length - 1)
                {
                    Mesh m2 = CylinderScript.BuildMesh(curves[z].Points[v], curves[z].Points[v + 1], lineRadius, lineRadius, vertexColor, new Vector3(0f, 90f, 0f), cylinderCapSegments, true);
                    m2 = NormalSolver.RecalculateNormals(m2, 75f);
                    CreateChildObject(parent, "Curve_" + z + "_Cylinder_" + v, m2, material);
                }
            }

            if (curves[z].ArrowAtStart)
            {
                Vector3 p0     = curves[z].Points[0];
                Vector3 p1     = curves[z].Points[1];
                Vector3 parrow = (p0 - p1).normalized * curves[z].ArrowLength + p0;
                Mesh    m      = CylinderScript.BuildMesh(p0, parrow, curves[z].ArrowRadius, 0f, vertexColor, new Vector3(0f, 90f, 0f), cylinderCapSegments, true);
                m = NormalSolver.RecalculateNormals(m, 75f);
                CreateChildObject(parent, "Curve_" + z + "_ArrowStart", m, material);
            }

            if (curves[z].ArrowAtEnd)
            {
                Vector3 p0     = curves[z].Points[curves[z].Points.Length - 1];
                Vector3 p1     = curves[z].Points[curves[z].Points.Length - 2];
                Vector3 parrow = (p0 - p1).normalized * curves[z].ArrowLength + p0;
                Mesh    m      = CylinderScript.BuildMesh(p0, parrow, curves[z].ArrowRadius, 0f, vertexColor, new Vector3(0f, 90f, 0f), cylinderCapSegments, true);
                m = NormalSolver.RecalculateNormals(m, 75f);
                CreateChildObject(parent, "Curve_" + z + "_ArrowEnd", m, material);
            }
        }
    }
Exemplo n.º 19
0
    private void Awake()
    {
        if (NetworkServer.active)
        {
            State[] stateValues = (State[])System.Enum.GetValues(typeof(State));
            foreach (State s in stateValues)
            {
                System.Type FSMType = System.Type.GetType(s.ToString());
                FSMState    state   = (FSMState)GetComponent(FSMType);
                if (null == state)
                {
                    state = (FSMState)gameObject.AddComponent(FSMType);
                }

                _states.Add(s, state);
                state.enabled = false;
            }
            _rigi     = GetComponent <Rigidbody>();
            _ss       = GetComponent <SphereScript>();
            _renderer = GetComponent <MeshRenderer>();
        }
    }
Exemplo n.º 20
0
    private Vector3 FindNormal(SphereScript sphere2)
    {
        Vector3 normal = new Vector3(0, 0, 0);

        float d = 0;

        d = (float)Math.Sqrt(Math.Pow(point1.x - point2.x, 2) + Math.Pow(point1.y - point2.y, 2) + Math.Pow(point1.z - point2.z, 2));

        if (d <= radius + sphere2.radius)
        {
            if (mass > sphere2.mass)
            {
                normal = (point2 - point1).normalized;
            }
            else
            {
                normal = -(point2 - point1).normalized;
            }
        }

        return(normal);
    }
Exemplo n.º 21
0
    void Start()
    {
        padScript    = GameObject.Find("Pad").GetComponent <PadScript>();
        sphereScript = GameObject.Find("Sphere").GetComponent <SphereScript>();
        cannon.SetActive(false);

        int index = 0;
        int x = 0, z = 0;

        for (int i = 0; i < 3; i++)
        {
            for (int j = 0; j < 12; j++)
            {
                float yPos = 0;
                bricks[index] = (Transform)Instantiate(prefabBrick, new Vector3(x, yPos, z), new Quaternion(0, 180, 0, 0));
                index++;
                x += 3;
            }
            x  = 0;
            z += -2;
        }
        _brickCounter = bricks.Length;
        _count        = 0;
    }
Exemplo n.º 22
0
    void Start()
    {
        padScript = GameObject.Find("Pad").GetComponent<PadScript>();
        sphereScript = GameObject.Find("Sphere").GetComponent<SphereScript>();
        cannon.SetActive(false);

        int index = 0;
        int x = 0, z = 0;

        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 12; j++)
            {
                float yPos = 0;
                bricks[index] = (Transform)Instantiate(prefabBrick, new Vector3(x, yPos, z), new Quaternion(0,180,0,0));
                index++;
                x += 3;
            }
            x=0;
            z += -2;
        }
        _brickCounter = bricks.Length;
        _count = 0;
    }
Exemplo n.º 23
0
    public void ResolveSphereCollision(SphereScript sphere2)
    {
        Vector3 normal = FindNormal(sphere2);
        float   d1     = Vector3.Dot((transform.position - sphere2.transform.position), normal) - (radius + sphere2.radius);

        point1 = transform.position;
        point2 = sphere2.transform.position;

        if (sphere2 != null)
        {
            float d2 = Vector3.Dot((transform.position - sphere2.transform.position), normal) - (radius + sphere2.radius);

            Vector3 par          = ParComp(velocity, normal);
            Vector3 perp         = PerpComp(velocity, normal);
            Vector3 momParComp   = Momentum(sphere2, par, normal);
            float   timeOfImpact = Time.deltaTime * (d1 / (d1 - d2));

            transform.position -= velocity * (Time.deltaTime - timeOfImpact);

            velocity = perp - coefficientOfRestitution * momParComp;

            transform.position += velocity * (Time.deltaTime - timeOfImpact);
        }
    }
Exemplo n.º 24
0
 /// <summary>
 /// Событие ухода сферы за пределы экрана
 /// </summary>
 /// <param name="sender">Sender.</param>
 void SphereOutOfScreenAction(SphereScript sender)
 {
     Destroy(sender.gameObject);
     NetworkManager.singleton.StopHost();
     NetworkServer.DisconnectAll();
 }
Exemplo n.º 25
0
 // Use this for initialization
 void Start()
 {
     hejsan  = GameObject.FindObjectOfType(typeof(SortingOfBlueprints)) as SortingOfBlueprints;
     hejsan2 = GameObject.FindObjectOfType(typeof(SphereScript)) as SphereScript;
 }
Exemplo n.º 26
0
 void Awake()
 {
     instance = this;
     cameraOrgSize = playerCamera.orthographicSize;
 }
Exemplo n.º 27
0
 private Vector3 Momentum(SphereScript s2, Vector3 par, Vector3 nor)
 {
     return(((mass - s2.mass) / (mass + s2.mass)) * par + ((2 * s2.mass) / (mass + s2.mass)) * s2.ParComp(s2.velocity, nor));
 }
Exemplo n.º 28
0
    void Start()
    {
        padScript = GameObject.Find("Pad").GetComponent<PadScript>();
        sphereScript = GameObject.Find("Sphere").GetComponent<SphereScript>();
        cannon.SetActive(false);

        GameObject brickArea = GameObject.Find("BrickArea");

        float brickWidth  = ( brickArea.renderer.bounds.size.x - brickWidthGap * (brickColumns - 1) ) / brickColumns;
        print (brickWidth);

        float brickHeight = ( brickArea.renderer.bounds.size.z - brickHeightGap * (brickRows - 1) ) / brickRows;
        print (brickHeight);

        Vector3 bricksStart = new Vector3();

        bricksStart = brickArea.transform.position -  brickArea.renderer.bounds.size/2;
        bricksStart.z = brickArea.transform.position.z +  brickArea.renderer.bounds.size.z/2;

        bricksStart.x += brickWidth / 2;
        bricksStart.z -= brickHeight / 2;

        print (bricksStart);

        int index = 0;
        float x = bricksStart.x, z = bricksStart.z;

        for(int i = 0; i < brickRows; i++)
        {
            for(int j = 0; j < brickColumns; j++)
            {
                float yPos = 0;

                bricks[index] = (Transform)Instantiate(prefabBrick, new Vector3(x, yPos, z), new Quaternion(0,180,0,0));
                bricks[index].localScale = new Vector3(brickWidth, bricks[index].localScale.y, brickHeight);
                index++;

                x +=  brickWidth + brickWidthGap;
            }
            x = bricksStart.x;// reset x bricks start to initial one

            z -= brickHeight + brickHeightGap;
        }

        _brickCounter = bricks.Length;
        _count = 0;
    }
Exemplo n.º 29
0
 public void AddSphere(SphereScript sphere)
 {
     //Adiciona o item que está sendo usado como parâmetro da função
     playerSpheres.Add(sphere);
     //Ativar comportamentos da esfera
 }