private void OnTriggerEnter(Collider other)
    {
        if (!active)
        {
            return;
        }
        TankScript hitTank = other.gameObject.GetComponent <TankScript>();

        if (hitTank != null && hitTank == shooter)
        {
            return;
        }
        else if (hitTank != null)
        {
            hitTank.TakeDamage(damage);
        }
        else if (other.GetComponent <IPoolable>() == null && other.GetComponent <Renderer>() != null)
        {
            RaycastHit hit;
            Vector3    hitPoint = other.ClosestPoint(transform.position);
            Physics.Raycast(transform.position, hitPoint - transform.position, out hit);
            GameObject crack = GameManager.Instance.CrackPool.GetObject(hitPoint + new Vector3(0f, 1f, 0f), Quaternion.LookRotation((hitPoint + new Vector3(0f, 1f, 0f)) - (decalOrigin.transform.position + new Vector3(0f, 1f, 0f))));
            crack.transform.LookAt(hitPoint + new Vector3(0f, 1f, 0f));
        }
        GameObject particles = Instantiate(impactParticles, transform.position, transform.rotation);

        AudioManager.Instance.SpawnSound("ImpactSound", particles.transform, true, false, false, 0.5f);
        GameManager.Instance.ProjectilePool.RePoolObject(gameObject);
    }
コード例 #2
0
    void CollisionFound(RaycastHit hit)
    {
        if (hit.collider.transform.parent)
        {
            BlockScript blockScript = hit.collider.transform.parent.GetComponent <BlockScript>();
            if (blockScript)
            {
                blockScript.WasHit(2);
            }
        }

        if (hit.collider.tag == "shield")
        {
            Destroy(gameObject);
            m_direction = Vector3.Reflect(m_direction, hit.normal);
        }
        else
        {
            if (hit.rigidbody)
            {
                TankScript tank = hit.rigidbody.GetComponent <TankScript>();
                if (tank)
                {
                    tank.Hit(gameObject);
                }
            }
            Bounce(hit.normal);
        }
    }
コード例 #3
0
    private TankScript _tankScript;      // Get public variables when needed.


    void Start()
    {
        if (GameObject.FindWithTag("Player") != null)
        {
            _tankScript = GameObject.FindWithTag("Player").GetComponent <TankScript>();
        }
        Destroy(gameObject, 2);
    }
コード例 #4
0
    void OnTriggerEnter2D(Collider2D col)
    {
        TankScript target = col.GetComponent <TankScript>();

        if (target != null)
        {
            target.Death();
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        TankScript tank = other.GetComponent <TankScript>();

        if (tank != null)
        {
            tank.TakeDamage(damage);
        }
    }
コード例 #6
0
    private void OnTriggerExit(Collider other)
    {
        TankScript tank = other.GetComponent <TankScript>();

        if (!mineActivated && tank != null)
        {
            mineActivated = true;
        }
    }
コード例 #7
0
    private void OnCollisionEnter(Collision collision)
    {
        TankScript tank = collision.gameObject.GetComponent <TankScript>();

        if (tank != null)
        {
            Instantiate(effectObject, transform.position, Quaternion.identity);
            Destroy(gameObject);
        }
    }
コード例 #8
0
 public void Init(TankScript target, TankScript shooter)
 {
     AudioManager.Instance.SpawnSound("MissileTravelSound", transform, false, false, false, 0.8f);
     this.target  = target;
     this.shooter = shooter;
     if (target != null)
     {
         agent.destination = target.transform.position;
     }
 }
コード例 #9
0
    private void OnCollisionEnter(Collision collision)
    {
        TankScript tank = collision.gameObject.GetComponent <TankScript>();

        if (tank != null)
        {
            tank.ChangeHealth(-damage);
        }
        Instantiate(explosionParticles, transform.position, transform.rotation);
        Destroy(gameObject);
    }
コード例 #10
0
    // Update is called once per frame
    void Update()
    {
        if (life > 0)
        {
            life -= Time.deltaTime;

            //check if bullet will hit anything in front of it because bullet moves too fast
            RaycastHit hit;
            if (Physics.Raycast(transform.position, transform.forward, out hit, 2.4f))
            {
                if (hit.transform.name == "Player(Clone)")
                {
                    if (Network.isServer)
                    {
                        PlayerScript script = hit.transform.gameObject.GetComponent("PlayerScript") as PlayerScript;
                        script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
                    }
                    destroy();
                }
                if (hit.transform.name == "Tank(Clone)")
                {
                    if (Network.isServer)
                    {
                        TankScript script = hit.transform.gameObject.GetComponent("TankScript") as TankScript;
                        script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
                    }
                    destroy();
                }
                if (hit.transform.name == "Jet(Clone)")
                {
                    if (Network.isServer)
                    {
                        JetScript script = hit.transform.gameObject.GetComponent("JetScript") as JetScript;
                        script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
                    }
                    destroy();
                }
                if (hit.transform.gameObject.tag == "Objective")
                {
                    if (Network.isServer)
                    {
                        ObjectiveScript script = hit.transform.parent.gameObject.GetComponent("ObjectiveScript") as ObjectiveScript;
                        script.objectiveHit(ad, sd);
                    }
                    destroy();
                }
            }
        }

        else
        {
            destroy();
        }
    }
コード例 #11
0
    // Start is called on initialization
    void Start()
    {
        // Get reference to our tank script
        tankScript = GetComponent<TankScript> ();

        // Start out with the firing on cooldown
        fireCooldown = fireFrequency;

        // Make the tank turn right all the time
        tankScript.SetTurnSpeed (1);
        tankScript.SetSpeed (1);
    }
コード例 #12
0
ファイル: SimpleBindingExample.cs プロジェクト: nvbvn/iceTest
        public void OnEnable()
        {
            m_Tank = GameObject.FindObjectOfType <TankScript>();
            if (m_Tank == null)
            {
                return;
            }

            var inspector = new InspectorElement(m_Tank);

            rootVisualElement.Add(inspector);
        }
コード例 #13
0
    // Start is called on initialization
    void Start()
    {
        // Get reference to our tank script
        tankScript = GetComponent <TankScript> ();

        // Start out with the firing on cooldown
        fireCooldown = fireFrequency;

        // Make the tank turn right all the time
        tankScript.SetTurnSpeed(1);
        tankScript.SetSpeed(1);
    }
コード例 #14
0
ファイル: AIInput.cs プロジェクト: shikoist/tanks
 private void Start()
 {
     mode = 1;
     ms = GameObject.Find("MainScript").GetComponent<MainScript>();
     x = 0;
     y = -1;
     direction = 2;
     ts = GetComponent<TankScript>();
     oldPosition = transform.position;
     cellX = Mathf.RoundToInt(oldPosition.x + 0.5f);
     cellY = Mathf.RoundToInt(oldPosition.z + 0.5f);
 }
コード例 #15
0
 private void Start()
 {
     mode        = 1;
     ms          = GameObject.Find("MainScript").GetComponent <MainScript>();
     x           = 0;
     y           = -1;
     direction   = 2;
     ts          = GetComponent <TankScript>();
     oldPosition = transform.position;
     cellX       = Mathf.RoundToInt(oldPosition.x + 0.5f);
     cellY       = Mathf.RoundToInt(oldPosition.z + 0.5f);
 }
コード例 #16
0
 public void TankDestroyed(TankScript tank)
 {
     if (tank is PlayerScript)
     {
         GameOver();
     }
     else
     {
         score += ((NpcScript)tank).Points;
         UIManager.Instance.AddScore(((NpcScript)tank).Points);
         WaveSpawner.Instance.TankDestroyed(tank.gameObject);
     }
 }
コード例 #17
0
    private void OnTriggerEnter(Collider other)
    {
        TankScript tank = other.GetComponent <TankScript>();

        if (tank != null)
        {
            tank.AddCoin();
            CoinManager.Instance.CoinPickedUp(gameObject);

            GameObject particles = Instantiate(coinPickupParticles, transform.position, Quaternion.identity);
            AudioManager.Instance.SpawnSound("CoinPickupSound", particles.transform, true, false, false, 1f);
        }
    }
 public void Init(Vector3 direction, float speed, TankScript parent, int damage)
 {
     active = true;
     foreach (ParticleSystem p in projectileParticles)
     {
         p.emissionRate = 200;
     }
     direction.y    = 0f;
     this.direction = direction;
     this.speed     = speed;
     this.shooter   = parent;
     this.damage    = damage;
     StartCoroutine("DestroyTimer");
 }
コード例 #19
0
    void SpawnTank(int player, GameObject moveTo)
    {
        TankScript tank = Instantiate <TankScript> (tankScript);

        tank.GetComponent <Renderer> ().material  = this.GetComponent <Renderer> ().material;
        tank.GetComponent <TankScript>().playerNo = playerNo;
        Vector3 position = moveTo.transform.position;

        gameplayObj.GetComponent <GamePlay> ().countrySide [target.GetComponent <HexMesh>().countryNo] = playerNo;
        position.y = 5.0f;
        tank.transform.localPosition = position;
        isSpawn = false;
        target  = null;
    }
コード例 #20
0
    void Awake()
    {
        tankRigidbody = gameObject.GetComponent <Rigidbody2D>();
        tankScript    = gameObject.GetComponent <TankScript>();

        if (tankRigidbody == null)
        {
            Debug.LogError("Missed Rigidbody");
        }

        if (tankScript == null)
        {
            Debug.LogError("Missed tankScript");
        }
    }
コード例 #21
0
    private void OnTriggerEnter(Collider other)
    {
        if (!mineActivated || !active)
        {
            return;
        }
        TankScript tank = other.GetComponent <TankScript>();

        if (tank != null)
        {
            tank.TakeDamage(damage);
            GameObject exp = Instantiate(explosion);
            AudioManager.Instance.SpawnSound("ExplosionSound", exp.transform, true, false, false, 0.658f);
            GameManager.Instance.MinePool.RePoolObject(gameObject);
        }
    }
コード例 #22
0
    private void OnTriggerEnter(Collider other)
    {
        TankScript hitTank     = other.GetComponent <TankScript>();
        IPoolable  hitPoolable = other.GetComponent <IPoolable>();

        if (hitTank != null && hitTank != shooter)
        {
            hitTank.TakeDamage(damage);
            GameObject exp = Instantiate(blast, transform.position, Quaternion.identity);
            AudioManager.Instance.SpawnSound("ExplosionSound", exp.transform, true, false, false, 0.658f);
            GameManager.Instance.MissilePool.RePoolObject(gameObject);
        }
        else if (hitPoolable != null)
        {
            GameManager.Instance.MissilePool.RePoolObject(gameObject);
        }
    }
コード例 #23
0
    public void TeleportPlayer()
    {
        TankScript player = PlayerScript.playerRef.transform.Find("Tank").GetComponent <TankScript>();

        player.GetComponent <Rigidbody>().velocity = new Vector3();

        player.GetComponent <Rigidbody>().MovePosition(transform.position + new Vector3(0, 1f, 0));
        PlayerScript.playerRef.GetComponent <PlayerScript>().startPos = transform.position;
        if (player.paused)
        {
            player.TeleportIn();
        }

        for (int i = 0; i < transform.childCount; i++)
        {
            transform.GetChild(i).gameObject.SetActive(false);
        }
    }
コード例 #24
0
 void Update()
 {
     if (!active || GameManager.Instance.Paused)
     {
         return;
     }
     sinPos     += Time.deltaTime;
     colorAmount = 0.5f + (Mathf.Lerp(-1, 1, Mathf.Sin(sinPos)) / 2);
     mat.SetColor("_EmissionColor", new Color(colorAmount, colorAmount, colorAmount));
     if (colorAmount == 0f)
     {
         sinPos = 0f;
     }
     if (target == null || (target is NpcScript && !(target as NpcScript).IsActive()))
     {
         if (WaveSpawner.Instance.CurrentWaveTanks.Count > 0)
         {
             target = WaveSpawner.Instance.CurrentWaveTanks[Random.Range(0, WaveSpawner.Instance.CurrentWaveTanks.Count)].GetComponent <TankScript>();
         }
         else
         {
             target = null;
             Vector3 newTarget = CoinManager.Instance.Coins[Random.Range(0, CoinManager.Instance.Coins.Length)].transform.position;
             newTarget.y       = transform.position.y;
             agent.destination = newTarget;
         }
     }
     if (target != null)
     {
         agent.destination = target.transform.position;
     }
     else if (Vector3.Distance(transform.position, agent.destination) < 0.1f)
     {
         Instantiate(blast, transform.position, Quaternion.identity);
         GameManager.Instance.MissilePool.RePoolObject(gameObject);
     }
 }
コード例 #25
0
 //bullet hits something
 void OnCollisionEnter(Collision hit)
 {
     if (Network.isServer)
     {
         if (hit.transform.gameObject.tag == "Objective")
         {
             ObjectiveScript script = hit.transform.parent.gameObject.GetComponent("ObjectiveScript") as ObjectiveScript;
             script.objectiveHit(ad, sd);
         }
         if (hit.transform.name == "Player(Clone)")
         {
             if (Network.isServer)
             {
                 PlayerScript script = hit.transform.gameObject.GetComponent("PlayerScript") as PlayerScript;
                 script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
             }
         }
         if (hit.transform.name == "Tank(Clone)")
         {
             if (Network.isServer)
             {
                 TankScript script = hit.transform.gameObject.GetComponent("TankScript") as TankScript;
                 script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
             }
         }
         if (hit.transform.name == "Jet(Clone)")
         {
             if (Network.isServer)
             {
                 JetScript script = hit.transform.gameObject.GetComponent("JetScript") as JetScript;
                 script.rpcGetHit(ad, sd, hit.transform.networkView.owner);
             }
         }
     }
     destroy();
 }
コード例 #26
0
 void Awake()
 {
     tank = GetComponent<TankScript>();
 }
コード例 #27
0
ファイル: Player.cs プロジェクト: Julow/unity_pool
	void			Start()
	{
		tankScript = GetComponent<TankScript>();
		canonDirection = tankScript.canon.transform.localRotation;
	}
コード例 #28
0
 private void Start()
 {
     ms = GameObject.Find("MainScript").GetComponent <MainScript>();
     ts = GetComponent <TankScript>();
 }
コード例 #29
0
 // Start is called on initialization
 void Start()
 {
     // Get reference to our tank script
     tankScript = GetComponent<TankScript> ();
 }
コード例 #30
0
ファイル: PlayerInput.cs プロジェクト: shikoist/tanks
 private void Start()
 {
     ms = GameObject.Find("MainScript").GetComponent<MainScript>();
     ts = GetComponent<TankScript>();
 }
コード例 #31
0
    public static void DemoOnGUI(TankScript tank)
    {
        // Save old global state.
        var oldColor = GUI.backgroundColor;

        // Create row style state for the background color.
        var background = new Texture2D(1, 1);

        background.SetPixel(0, 0, new Color(0.18f, 0.18f, 0.18f));
        background.Apply();
        var state = new GUIStyleState();

        state.background = background;

        // Create row style.
        var rowStyle = new GUIStyle();

        rowStyle.margin = new RectOffset(0, 0, 6, 6);
        rowStyle.normal = state;

        using (var rowScope = new GUILayout.HorizontalScope(rowStyle))
        {
            // Create label style from the default skin.
            var labelStyle = new GUIStyle(GUI.skin.label);
            labelStyle.fontSize    = 20;
            labelStyle.fontStyle   = FontStyle.Bold;
            labelStyle.fixedHeight = labelStyle.CalcHeight(GUIContent.none, 1);

            // Draw the label.
            EditorGUILayout.LabelField(
                "IMGUI",
                labelStyle,
                GUILayout.Width(136),
                GUILayout.Height(labelStyle.fixedHeight));

            // Set font size and style.
            var fieldStyle = new GUIStyle(GUI.skin.textField);
            fieldStyle.fontSize    = 20;
            fieldStyle.fontStyle   = FontStyle.Bold;
            fieldStyle.fixedHeight = fieldStyle.CalcHeight(GUIContent.none, 1);

            // Determine TextField background color from mouse position.
            var rect = EditorGUILayout.GetControlRect(GUILayout.MinWidth(0.0f));
            rect.height = fieldStyle.fixedHeight;
            if (rect.Contains(Event.current.mousePosition))
            {
                GUI.backgroundColor = Color.yellow;
            }

            // Draw TextField
            tank.tankName =
                EditorGUI.TextField(rect, tank.tankName, fieldStyle);

            // Draw IntField
            GUI.backgroundColor = Color.blue;
            tank.tankSize       =
                EditorGUILayout.IntField(
                    tank.tankSize,
                    fieldStyle,
                    GUILayout.Width(94),
                    GUILayout.Height(fieldStyle.fixedHeight));
        }

        // Restore global state.
        GUI.backgroundColor = oldColor;
    }
コード例 #32
0
    //
    //
    //

    public void OnEnable()
    {
        m_Tank = GameObject.FindObjectOfType <TankScript>();
    }
コード例 #33
0
    public void OnEnable()
    {
        m_Tank = GameObject.FindObjectOfType <TankScript>();
        if (m_Tank == null)
        {
            return;
        }

        var root = rootVisualElement;

        #region Inline C#
        //
        //
        //

        var inlineVE = new VisualElement()
        {
            style =
            {
                marginBottom    =                 2,
                paddingLeft     =                 4,
                flexDirection   = FlexDirection.Row,
                backgroundColor = new Color(0.18f, 0.18f, 0.18f),
            }
        };

        // Label
        inlineVE.Add(new Label()
        {
            text  = "Inline C#",
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                width                   = 140
            }
        });

        // TextField
        inlineVE.Add(new TextField()
        {
            value = m_Tank.tankName,
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                flexGrow                = 1
            }
        });

        // IntegerField
        inlineVE.Add(new IntegerField()
        {
            value = m_Tank.tankSize,
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                width           =            100,
                backgroundColor = Color.blue
            }
        });

        root.Add(inlineVE);

        //
        //
        //
        #endregion Inline C#

        #region C# + USS
        //
        //
        //

        var ussVE = new VisualElement()
        {
            name = "row"
        };
        ussVE.AddToClassList("container");
        ussVE.styleSheets.Add(Resources.Load <StyleSheet>("Basics/basics_styles"));

        ussVE.Add(new Label()
        {
            text = "USS"
        });
        ussVE.Add(new TextField()
        {
            value = m_Tank.tankName
        });
        ussVE.Add(new IntegerField()
        {
            value = m_Tank.tankSize
        });

        root.Add(ussVE);

        //
        //
        //
        #endregion C# + USS

        #region C# + USS + UXML
        //
        //
        //

        var visualTree = Resources.Load("Basics/basics_uxml") as VisualTreeAsset;
        var uxmlVE     = visualTree.CloneTree();

        root.Add(uxmlVE);

        //
        //
        //
        #endregion C# + USS + UXML

        #region UQuery
        //
        //
        //

        uxmlVE.Q <TextField>().value    = m_Tank.tankName;
        uxmlVE.Q <IntegerField>().value = m_Tank.tankSize;
        var textFields    = root.Query <TextField>();
        var integerFields = root.Query <IntegerField>();

        //
        //
        //
        #endregion UQuery

        #region Events
        //
        //
        //

        inlineVE.Q <TextField>().RegisterCallback <MouseEnterEvent>(
            e => (e.target as VisualElement)
            .style.backgroundColor = Color.yellow);

        inlineVE.Q <TextField>().RegisterCallback <MouseLeaveEvent>(
            e => (e.target as VisualElement)
            .style.backgroundColor = Color.clear);

        var textFieldList = textFields.ToList();
        foreach (var field in textFieldList)
        {
            field.RegisterCallback <ChangeEvent <string> >(
                e => m_Tank.tankName =
                    (e.target as TextField).value);
        }

        integerFields.ForEach(field =>
                              field.RegisterValueChangedCallback(
                                  e => m_Tank.tankSize = e.newValue));

        //
        //
        //
        #endregion Events

        #region Scheduler
        //
        //
        //

        root.schedule.Execute(() =>
        {
            textFields.ForEach(t => t.value    = m_Tank.tankName);
            integerFields.ForEach(t => t.value = m_Tank.tankSize);
        }).Every(100);

        //
        //
        //
        #endregion Scheduler

        #region Bindings
        //
        //
        //

        var boundVisualTree = Resources.Load("Inspector/inspector_uxml") as VisualTreeAsset;
        var boundVE         = boundVisualTree.CloneTree();

        boundVE.Bind(new SerializedObject(m_Tank));

        root.Add(boundVE);

        //
        //
        //
        #endregion Bindings

        #region IMGUI
        //
        //
        //

        var imguiContainer = new IMGUIContainer(() =>
        {
            IMGUIDemoWindow.DemoOnGUI(m_Tank);
        });

        root.Add(imguiContainer);

        //
        //
        //
        #endregion IMGUI

        #region Background Image
        root.style.overflow = Overflow.Hidden;
        var backgroundTexture = Resources.Load <Texture2D>("Basics/blue_tank");
        var background        = new VisualElement()
        {
            name  = "background",
            style =
            {
                backgroundImage = backgroundTexture,
                position        = Position.Absolute,
                bottom          =                 0,
                right           =                 0,
                width           =               250,
                height          = 250
            }
        };
        root.Insert(0, background);
        root.styleSheets.Add(Resources.Load <StyleSheet>("Basics/fixes"));
        boundVE.styleSheets.Add(Resources.Load <StyleSheet>("Inspector/inspector_styles"));
        #endregion
    }
コード例 #34
0
    public void OnEnable()
    {
        m_Tank = GameObject.FindObjectOfType <TankScript>();
        if (m_Tank == null)
        {
            return;
        }

        var root = rootVisualElement;

        #region Inline C#
        //
        //
        //

        var inlineVE = new VisualElement()
        {
            style =
            {
                marginTop       =                 6,
                marginBottom    =                 6,
                flexDirection   = FlexDirection.Row,
                backgroundColor = new Color(0.3f, 0.3f, 0.3f),
            }
        };

        // Label
        inlineVE.Add(new Label()
        {
            text  = "Inline C#",
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                width                   = 140
            }
        });

        // TextField
        inlineVE.Add(new TextField()
        {
            value = m_Tank.tankName,
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                flexGrow                = 1
            }
        });

        // IntegerField
        inlineVE.Add(new IntegerField()
        {
            value = m_Tank.tankSize,
            style =
            {
                fontSize                =             20,
                unityFontStyleAndWeight = FontStyle.Bold,
                width           =            100,
                backgroundColor = Color.blue
            }
        });

        root.Add(inlineVE);

        //
        //
        //
        #endregion Inline C#

        #region C# + USS
        //
        //
        //

        var ussVE = new VisualElement()
        {
            name = "row"
        };
        ussVE.AddToClassList("container");
        ussVE.styleSheets.Add(Resources.Load <StyleSheet>("Basics/basics_styles"));

        ussVE.Add(new Label()
        {
            text = "USS"
        });
        ussVE.Add(new TextField()
        {
            value = m_Tank.tankName
        });
        ussVE.Add(new IntegerField()
        {
            value = m_Tank.tankSize
        });

        root.Add(ussVE);

        //
        //
        //
        #endregion C# + USS

        #region C# + USS + UXML
        //
        //
        //

        var visualTree = Resources.Load("Basics/basics_uxml") as VisualTreeAsset;
        var uxmlVE     = visualTree.CloneTree();
        uxmlVE.styleSheets.Add(Resources.Load <StyleSheet>("Basics/basics_styles"));

        root.Add(uxmlVE);

        //
        //
        //
        #endregion C# + USS + UXML

        #region UQuery
        //
        //
        //

        uxmlVE.Q <TextField>().value    = m_Tank.tankName;
        uxmlVE.Q <IntegerField>().value = m_Tank.tankSize;
        var textFields    = root.Query <TextField>();
        var integerFields = root.Query <IntegerField>();

        //
        //
        //
        #endregion UQuery

        #region Events
        //
        //
        //

        inlineVE.Q <TextField>().RegisterCallback <MouseEnterEvent>(
            e => (e.target as VisualElement)
            .style.backgroundColor = Color.yellow);

        inlineVE.Q <TextField>().RegisterCallback <MouseLeaveEvent>(
            e => (e.target as VisualElement)
            .style.backgroundColor = Color.clear);

        var textFieldList = textFields.ToList();
        foreach (var field in textFieldList)
        {
            field.RegisterCallback <ChangeEvent <string> >(
                e => m_Tank.tankName =
                    (e.target as TextField).value);
        }

        integerFields.ForEach(field =>
                              field.RegisterValueChangedCallback(
                                  e => m_Tank.tankSize = e.newValue));

        //
        //
        //
        #endregion Events

        #region Scheduler
        //
        //
        //

        var scheduledAction = root.schedule.Execute(() =>
        {
            textFields.ForEach(t => t.value    = m_Tank.tankName);
            integerFields.ForEach(t => t.value = m_Tank.tankSize);
        });
        scheduledAction.Every(100); // ms

        //
        //
        //
        #endregion Scheduler

        #region Bindings
        //
        //
        //

        var inspector = new InspectorElement(m_Tank);

        // TODO: Ignore this bit. It's to account for a bug.
        // Once fixed, this code will not be necessary anymore.
        inspector.RemoveFromClassList("unity-inspector");
        inspector.Query <PropertyField>().ForEach((pf) =>
        {
            pf.Q <Label>().RemoveFromHierarchy();
            pf.Q(className: "unity-property-field__input").style.flexGrow = 1;
        });

        root.Add(inspector);

        //
        //
        //
        #endregion Bindings

        #region IMGUI
        //
        //
        //

        var imguiContainer = new IMGUIContainer(() =>
        {
            IMGUIDemoWindow.DemoOnGUI(m_Tank);
        });

        root.Add(imguiContainer);

        //
        //
        //
        #endregion IMGUI

        #region Background Image
        root.style.overflow = Overflow.Hidden;
        var backgroundTexture = Resources.Load <Texture2D>("Basics/blue_tank");
        var background        = new VisualElement()
        {
            name  = "background",
            style =
            {
                backgroundImage = backgroundTexture,
                position        = Position.Absolute,
                bottom          =                 0,
                right           =                 0,
                width           =               250,
                height          = 250
            }
        };
        root.Insert(0, background);
        #endregion
    }
コード例 #35
0
    private void OnTriggerEnter(Collider otherCollider)
    {
        if (!(otherCollider.tag == "Tank"))
        {
            return;
        }
        TankScript tankScript = otherCollider.transform.GetComponent <TankScript>();

        if (tankScript.ally == "Player")
        {
            if (!ms.noSound)
            {
                audio.Play();
            }
            Player player = ms.playersList[tankScript.number];
            player.scores += 500;
            player.kills[4]++;
            ms.ShowFlower(transform.position, "500");
            switch (type)
            {
            case Bonus.Life:
            {
                player.lifes++;
                break;
            }

            case Bonus.Upgrade:
                if (tankScript.rank < 3)
                {
                    tankScript.Upgrade(1);
                    break;
                }
                else
                {
                    break;
                }

            case Bonus.Bomb:
                ms.DestroyAllEnemy();
                break;

            case Bonus.Freeze:
                ms.FreezeAllEnemy();
                break;

            case Bonus.Fort:
                ms.UpgradeFort();
                break;

            case Bonus.Shield:
            {
                tankScript.invincible = 10;
                break;
            }

            case Bonus.FullUpgrade:
            {
                if (tankScript.rank < 3)
                {
                    tankScript.Upgrade(3);
                }
                break;
            }

            case Bonus.Ship:
            {
                tankScript.SetWaterWalking(true);
                break;
            }
            }
            Hide();
        }
        if (!(tankScript.ally == "Enemy") || ms.difficulty != 2)
        {
            return;
        }
        switch (type)
        {
        case Bonus.Life:
            if (tankScript.rank < 3)
            {
                tankScript.Upgrade(3);
                break;
            }
            else
            {
                break;
            }

        case Bonus.Upgrade:
            if (tankScript.rank < 3)
            {
                tankScript.Upgrade(1);
                break;
            }
            else
            {
                break;
            }

        case Bonus.Bomb:
            ms.DestroyAllPlayers();
            break;

        case Bonus.Freeze:
            ms.FreezeAllPlayers();
            break;

        case Bonus.Fort:
            ms.ClearUpgradeFort();
            break;

        case Bonus.Shield:
            if (tankScript.rank < 3)
            {
                tankScript.Upgrade(3);
                break;
            }
            else
            {
                break;
            }

        case Bonus.FullUpgrade:
            if (tankScript.rank < 3)
            {
                tankScript.Upgrade(3);
                break;
            }
            else
            {
                break;
            }

        case Bonus.Ship:
        {
            tankScript.SetWaterWalking(true);
            break;
        }
        }
        Hide();
    }
コード例 #36
0
 // Use this for initialization
 void Start()
 {
     tankScript = GetComponent <TankScript>();
 }