Esempio n. 1
0
        public async Task <IActionResult> Edit(int id, [Bind("PlanesId,ClassesId")] PlaneUnit planeUnit)
        {
            if (id != planeUnit.PlanesId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(planeUnit);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlaneUnitExists(planeUnit.PlanesId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(planeUnit));
        }
Esempio n. 2
0
        public async Task <IActionResult> Create([Bind("PlanesId,ClassesId")] PlaneUnit planeUnit)
        {
            if (ModelState.IsValid)
            {
                _context.Add(planeUnit);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(planeUnit));
        }
Esempio n. 3
0
    public void CreateUnit(GameObject prefab)
    {
        Vector3 initialPosition = this.playerBase.transform.position;

        if (prefab.GetComponent <CannonUnit>() != null)
        {
            if (this.plane != null)
            {
                this.plane.rigidbody.position += new Vector3(0, 0.6f, 0);
            }
            initialPosition += this.playerBase.transform.up * (3 + this.numberOfCannons * 0.5f) + this.playerBase.transform.right * 1;
            this.numberOfCannons++;
        }

        if (prefab.GetComponent <PlaneUnit>() != null)
        {
            if (this.plane != null)
            {
                this.plane.StartStrike();
                return;
            }
            else
            {
                initialPosition += this.playerBase.transform.up * (3 + this.numberOfCannons * 0.5f) + this.playerBase.transform.right * 1.5f;
            }
        }

        GameObject unit = Object.Instantiate(
            prefab,
            initialPosition,
            new Quaternion(0, 0, 0, 0)
            ) as GameObject;

        unit.GetComponent <OwnedObject>().owner = this;

        if (unit.GetComponent <PlaneUnit>() != null)
        {
            this.plane = unit.GetComponent <PlaneUnit>();
        }

        foreach (Renderer renderer in unit.GetComponentsInChildren <Renderer>())
        {
            renderer.material.color = this.color;
        }
    }