// Use this for initialization void Start() { isGameOver = false; restart = true; player1controller = player1.GetComponent<Player1Controller>(); player2controller = player2.GetComponent<Player2Control>(); }
void OnTriggerEnter2D(Collider2D hit) { if (hit.gameObject.tag == "Player") { Player2Control script = hit.GetComponent <Player2Control>(); if (script != null) { script.doubleJump = true; cooldown = 120; this.gameObject.renderer.enabled = false; this.gameObject.collider2D.enabled = false; } Player1Control script2 = hit.GetComponent <Player1Control>(); if (script2 != null) { script2.doubleJump = true; cooldown = 120; this.gameObject.renderer.enabled = false; this.gameObject.collider2D.enabled = false; } } }
private moveGrounds mG; //地面的脚本 // Start is called before the first frame update void Start() { //获得两个player的脚本对象 moveScript = GameObject.FindWithTag("player").GetComponent <PlayerControl>(); moveScript_2 = GameObject.FindWithTag("player_2").GetComponent <Player2Control>(); mG = GameObject.FindWithTag("grounds").GetComponent <moveGrounds>(); }
void Start() { check = player.GetComponent <Player2Control>(); render1 = health[0].GetComponent <SpriteRenderer>(); render2 = health[1].GetComponent <SpriteRenderer>(); render3 = health[2].GetComponent <SpriteRenderer>(); }
// Start is called before the first frame update void Start() { Debug.Log("1 Initing!!!!!!!!!!!!!!!!!!!!!!!!!!"); playerHealth = GameObject.Find("PlayerHealth"); rigidbody = GetComponent <Rigidbody2D>(); if (player.name.Equals("player1")) { KeyCodeSet[0] = KeyCode.W; KeyCodeSet[1] = KeyCode.A; KeyCodeSet[2] = KeyCode.S; KeyCodeSet[3] = KeyCode.D; KeyCodeSet[4] = KeyCode.J; KeyCodeSet[5] = KeyCode.K; KeyCodeSet[6] = KeyCode.U; KeyCodeSet[7] = KeyCode.I; KeyCodeSet[8] = KeyCode.O; KeyCodeSet[9] = KeyCode.L; } if (player.name.Equals("player2")) { KeyCodeSet[0] = KeyCode.UpArrow; KeyCodeSet[1] = KeyCode.LeftArrow; KeyCodeSet[2] = KeyCode.DownArrow; KeyCodeSet[3] = KeyCode.RightArrow; KeyCodeSet[4] = KeyCode.Keypad1; KeyCodeSet[5] = KeyCode.Keypad2; KeyCodeSet[6] = KeyCode.Keypad4; KeyCodeSet[7] = KeyCode.Keypad5; KeyCodeSet[8] = KeyCode.Keypad6; KeyCodeSet[9] = KeyCode.Keypad3; } animator = GetComponent <Animator>(); animation = GetComponent <Animation>(); ac1 = GetComponent <AnimationCreator>().Create("attack"); ac2 = GetComponent <AnimationCreator>().Create("Guard"); ac3 = GetComponent <AnimationCreator>().Create("attack2"); throwArea = GameObject.Find(name + "/Skeleton/rootBone/rightArm/rightArm2/rightHand/throwArea"); bluebar = GameObject.FindWithTag("BlueBar_1").GetComponent <BlueBar>(); gems[0] = GameObject.FindWithTag("Gem_1_1").GetComponent <Gem>(); gems[1] = GameObject.FindWithTag("Gem_1_2").GetComponent <Gem>(); gems[2] = GameObject.FindWithTag("Gem_1_3").GetComponent <Gem>(); playerHealth.GetComponent <PlayerHealth>().init(); BattlePara.Init(); //整合的(设置Tag) moveScript_2 = GameObject.FindWithTag("player_2").GetComponent <Player2Control>(); //riBody = GetComponent<Rigidbody2D>();//用来处理抖动的问题 mG = GameObject.FindWithTag("grounds").GetComponent <moveGrounds>(); }
void OnTriggerStay2D(Collider2D hit) { if (hit.gameObject.tag == "Player") { Player2Control script = hit.GetComponent <Player2Control>(); if (script != null) { script.doubleJump = true; } Player1Control script2 = hit.GetComponent <Player1Control>(); if (script2 != null) { script2.doubleJump = true; } } }
void OnCollisionStay2D(Collision2D collision) { if (collision.gameObject.tag == "Floor") { Player1Control par1 = GetComponentInParent <Player1Control>(); if (par1 != null) { if (!((collision.transform.eulerAngles.z > 40) && (collision.transform.eulerAngles.z < 320))) { par1.Rotate(collision.transform.eulerAngles); } } Player2Control par2 = GetComponentInParent <Player2Control>(); if (par2 != null) { if (!((collision.transform.eulerAngles.z > 40) && (collision.transform.eulerAngles.z < 320))) { par2.Rotate(collision.transform.eulerAngles); } } if (Input.GetAxis("Player1_Jump") > 0) { if (par1 != null) { par1.Jump(); return; } } if (Input.GetAxis("Player2_Jump") > 0) { if (par2 != null) { par2.Jump(); return; } } } }
void OnTriggerEnter2D(Collider2D hit) { if (hit.gameObject.tag == "Player") { Player2Control script = hit.GetComponent <Player2Control>(); if (script != null) { script.speed /= 1.15f; script.speedBoost = 360; } Player1Control script2 = hit.GetComponent <Player1Control>(); if (script2 != null) { script2.speed /= 1.15f; script2.speedBoost = 360; } GameObject.Destroy(this.gameObject); } }
// Start is called before the first frame update void Start() { p1Rigid = GameObject.Find("/player1").GetComponent <Rigidbody2D>(); p2Rigid = GameObject.Find("/player2").GetComponent <Rigidbody2D>(); //p1Rigid.WakeUp(); p2Rigid.WakeUp(); p1Rigid.gravityScale = 1; p2Rigid.gravityScale = 1; p1Bc = GameObject.Find("/player1").GetComponent <BoxCollider2D>(); p1Bc.enabled = true; p1Animator = GameObject.Find("/player1").GetComponent <Animator>(); p1Animator.enabled = true; p1c = GameObject.Find("/player1").GetComponent <PlayerControl>(); p1c.enabled = true; p1Ac = GameObject.Find("/player1").GetComponent <AnimationCreator>(); p1Ac.enabled = true; p2Bc = GameObject.Find("/player2").GetComponent <BoxCollider2D>(); p2Bc.enabled = true; p2Animator = GameObject.Find("/player2").GetComponent <Animator>(); p2Animator.enabled = true; p2c = GameObject.Find("/player2").GetComponent <Player2Control>(); p2c.enabled = true; p2Ac = GameObject.Find("/player2").GetComponent <AnimationCreator>(); p2Ac.enabled = true; GameObject.Find("/Grass").GetComponent <SpriteRenderer>().sortingOrder = 0; canvasGroup = GetComponent <CanvasGroup>(); stopButton = transform.Find("stopButton").GetComponent <Button>(); stopButton.onClick.AddListener(OnStopClick); }
private InHand Interact() { Ray lookAt = new Ray(transform.position, transform.forward); Debug.DrawRay(lookAt.origin, 15 * lookAt.direction, Color.red, 5); RaycastHit info; //the Array only works if it is in the range of 'raycastRange' if (Physics.Raycast(lookAt, out info, raycastRange)) { BarellController barrell = info.collider.GetComponent <BarellController>(); if (barrell)//if it has the script 'PlantsController' do this { if (currently_Holding == InHand.Empty) { BarellController.PlantType pickingUP = barrell.pickUp(); switch (pickingUP) { case BarellController.PlantType.Carrot: return(InHand.Carrot_Seeds); case BarellController.PlantType.Tomatoe: return(InHand.Tomatoe_Seeds); } } } plotControl plot = info.collider.GetComponent <plotControl>(); if (plot) { //Seed planting if (currently_Holding == InHand.Carrot_Seeds || currently_Holding == InHand.Tomatoe_Seeds) { if (plot.plotIs == plotControl.PlotState.Soil) { plot.Interact(currently_Holding); return(InHand.Empty); } } //plucker for removing the rubbish (grass) if (currently_Holding == InHand.Plucker) { if (plot.plotIs == plotControl.PlotState.Rubbish) { plot.Interact(currently_Holding); return(InHand.Plucker); } } //Once the plant is grown (tomato) if (currently_Holding == InHand.Empty) { if (plot.plotIs == plotControl.PlotState.Tomatoe_Plant) { plot.Interact(currently_Holding); return(InHand.Tomatoes); } } //Once the plant is grown (carrots) (so that the player could pick up the item) if (currently_Holding == InHand.Empty) { if (plot.plotIs == plotControl.PlotState.Carrot_Plant) { plot.Interact(currently_Holding); return(InHand.Carrots); } } } TrashController trash = info.collider.GetComponent <TrashController>(); if (trash) { return(InHand.Empty); } PluckerControl plucker = info.collider.GetComponent <PluckerControl>(); if (plucker) { if (currently_Holding == InHand.Empty) { return(InHand.Plucker); } } TableController table = info.collider.GetComponent <TableController>(); if (table) { if (currently_Holding == InHand.Empty) { if (table.SomethingOnTable()) { GameObject item = table.removeTopItem(); //add the script to the tomato and carrots prefab and add it to the table, + delete an extra table VegControl newplant = item.GetComponent <VegControl>(); if (newplant) { switch (newplant.thisIsA) { case VegControl.VegType.Carrot: return(InHand.Carrots); case VegControl.VegType.Tomatoe: return(InHand.Tomatoes); } } } } else { if (currently_Holding == InHand.Carrots) { table.putCarrotOn(); return(InHand.Empty); } if (currently_Holding == InHand.Tomatoes) { table.putTomatoOn(); return(InHand.Empty); } } } P2WagonController wagon = info.collider.GetComponent <P2WagonController>(); if (wagon) { { if (currently_Holding == InHand.Carrots) { wagon.putCarrotOn(); return(InHand.Empty); } if (currently_Holding == InHand.Tomatoes) { wagon.putTomatoOn(); return(InHand.Empty); } } } Player2Control playerHit = info.collider.GetComponent <Player2Control>(); if (playerHit) { GameObject player2; if (currently_Holding == InHand.Plucker) { if (player2 = GameObject.FindWithTag("Player2")) { player2.transform.position = new Vector3(playerHit.transform.position.x, transform.position.y + 7, transform.position.z); } } } } return(currently_Holding); }
void Start() { check = player.GetComponent <Player2Control>(); render = GetComponent <SpriteRenderer>(); }