private void Awake() { domina = GetComponent <DominaAttribute>(); humenAttribute = GameObject.FindWithTag("Player").GetComponent <HumenAttributeManage>(); placeDomina = GameObject.FindWithTag("Player").GetComponent <PlaceDomina>(); view = GameObject.Find("ViewManagment").GetComponent <ExtraMessageView>(); rigidbody = GetComponent <Rigidbody>(); player = GameObject.FindWithTag("Player").GetComponent <Transform>(); }
// Update is called once per frame void Update() { // 只有准备好放置才会出现后面的情况 if (!IfPreparePlace) { return; } dominaAttribute = humenAttribute.DominaModel; ifCollider = false; dominaModel.localScale = new Vector3(dominaAttribute.xScale, dominaAttribute.yScale, dominaAttribute.zScale); Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Floor")) { // 如果是地板的话,才可以放置 // 首先在在碰撞点生成一个绿色透明的多米诺骨牌,表示将要放置的多米诺骨牌 dominaModel.transform.position = new Vector3(hit.point.x, dominaAttribute.yScale / 2, hit.point.z); ifCollider = true; // 如果按下R键,则可以将该多米诺骨牌绕Y咒向右旋转 if (Input.GetKey(KeyCode.R)) { dominaModel.Rotate(0, 1, 0); } if (Input.GetKey(KeyCode.E)) { dominaModel.Rotate(0, -1, 0); } nowRotation = dominaModel.rotation; nowTransform = dominaModel.position; if (Input.GetButtonDown("Fire1")) { if (Vector3.Distance(hit.point, transform.position) > 3f) { extraView.ShowExtraMessage("目标地点距离角色太远了!请走进一点再放置多米诺骨牌"); } else { domina = humenAttribute.Cube; //GameObject cube = GameObject.Instantiate<GameObject>(domina, nowTransform, nowRotation); //domina.SetActive(true); domina.transform.position = nowTransform; domina.transform.rotation = nowRotation; humenAttribute.IsGetCube = false; IfPreparePlace = false; dominaModel.position = originPositionModel; } } } } if (!ifCollider) { dominaModel.position = originPositionModel; } }