public IHttpActionResult PostVehicle(CarFront vehicle) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <Service> listaServisa = (List <Service>)unitOfWork.Services.GetAll(); Vehicle zaBazu = new Vehicle(); zaBazu.Description = vehicle.Description; zaBazu.Maker = vehicle.Maker; zaBazu.Model = vehicle.Model; zaBazu.YearOfMaking = vehicle.YearOfMaking; foreach (var sc in listaServisa) { if (sc.Name == vehicle.ServiceName) { zaBazu.ServiceId = sc.Id; break; } } unitOfWork.Vehicles.Add(zaBazu); unitOfWork.Complete(); return(CreatedAtRoute("DefaultApi", new { id = zaBazu.VehicleId }, zaBazu)); }
public void Explode() { if (CarBody == null) { return; } CF.position = new Vector3(CF.position.x, CF.position.y + 2, CF.position.z); CR.position = new Vector3(CF.position.x, CF.position.y - 2, CF.position.z); CC.position = new Vector3(CF.position.x + 2, CF.position.y, CF.position.z); CarFront.transform.position = new Vector3(CarFront.transform.position.x, CarFront.transform.position.y + 2, CarFront.transform.position.z); // Core Rigidbody CarBodyBody = CarBody.AddComponent <Rigidbody>(); BoxCollider carBodyCollider = CarBody.AddComponent <BoxCollider>(); carBodyCollider.size = new Vector3(0.5f, 0.5f, 0.5f); var locVel = transform.InverseTransformDirection(CarBodyBody.velocity); locVel.y += 12; locVel.x += 2; CarBodyBody.velocity = transform.TransformDirection(locVel); CoreFire.Play(); // Front Rigidbody CarFrontBody = CarFront.AddComponent <Rigidbody>(); BoxCollider carFrontCollider = CarFront.AddComponent <BoxCollider>(); carFrontCollider.size = new Vector3(0.5f, 0.5f, 0.5f); locVel = transform.InverseTransformDirection(CarFrontBody.velocity); locVel.z += 8; locVel.y += 6; CarFrontBody.velocity = transform.TransformDirection(locVel); FrontFire.Play(); // Rear Rigidbody CarRearBody = CarRear.AddComponent <Rigidbody>(); BoxCollider carRearCollider = CarRear.AddComponent <BoxCollider>(); carRearCollider.size = new Vector3(0.5f, 0.5f, 0.5f); locVel = transform.InverseTransformDirection(CarRearBody.velocity); locVel.z -= 8; locVel.y += 6; CarRearBody.velocity = transform.TransformDirection(locVel); RearFire.Play(); Destroy(wheels); Destroy(boosts); //transform.DetachChildren(); // crash }